当前位置 > 首页 > Asp.net

Sitecore Item Web API and Json.Net Test Drive (Part II –Strongly Typed)

2012-11-19 11:27:00来源:Asp.net

In the earlier post I did related to this topic, I have talked about using Json.Net to consume the result of Sitecore Item Web API. In that post, I have used the keyword dynamic to express my intention of consuming the returned json of the API.

In this article, I will create some useful classes to write our implementation of consuming the API using strongly-typed. We will start of with the Record class which will hold the top most elements the API will present us.

Record class

Pretty straight forward class. It has 2 properties to hold the statuscode and the result elements. If you intend to use a different property name in your class from the json property, you can do so by passing a string literal of the json property name to the JsonProperty attribute and name your class property differently.

If you look at the earlier post, you will notice that the API returns an array of items that contains all of the Sitecore content item or items and stores them under the result->items array element. To be able to map that array of items, we have to write a collection property and decorate that with the JsonProperty attribute.

Result class

The JsonItem class is a simple class which will map to the corresponding item property contained in the array. If you notice, these properties are just the basic Sitecore fields.

JsonItem class

And here’s the main portion of this post that will binds them all together.

Main

And here’s the output of this code.

Output

In closing, the same result can be achieved using the dynamic keyword or defining classes to map the json propery returned by the Sitecore Item Web API. With a little bit more of coding, you can take advantage of power of strongly-typed solution.

Have a good week ahead of you.



  • Resize Images Without Loss Of Quality in ASP.NET

    2011-5-3 19:11:00

    To create a image Gallery for your site, you may need to re size your image before uploading. And h

  • Mobile开发(九宫格控件)

    2009-6-18 21:21:00

    Mobile开发个人感觉使用九宫格的时候并不多,但有时候又不得不使用,有点类似于手机开发标志性的控件了,客户指明要用,咱们还能说啥。 老规矩,先上控件,控件竖屏时显示为九格,横屏时显示为八格,

  • .NET 动态脚本语言Script.NET 应用举例

    2011-9-15 20:18:00

    继续前面的两篇文章的动态脚本语言主题《 .NET 动态脚本语言Script.NET 入门指南 Quick Start 》和《 .NET 动态脚本语言Script.NET 开发指南 》,继续学习Scr

  • Office 2007 风格的TextBox的实现

    2009-5-17 1:43:00

    Office 2007 风格的TextBox的实现 简单实现一个Office 2007风格的TextBox。样式如下图。 实现的关键是,在UserControl上面放一个Te

  • 异常处理准则

    2010-1-20 0:13:00

    阅读: 569 评论: 9 作者: 麒麟 发表于 2010-01-19 20:04 原文链接 在开发应用程序的时候,异常处理是非常的重要的,我找到一些异常处理准则,将它共享出来,如有不同

  • 提取国家地理图片总结之二

    2009-9-5 2:17:00

    只有注册用户登录后才能阅读该文, 阅读全文 。

  • Asp.net Mvc分页方法介绍

    2011-2-3 22:34:00

    在项目用MVC开发也很久了,今天整理了下分页的方法,写个DEMO供大家交流参考下。 首先来看页面图片效果: 下面是项目文件截图: 在mvcweb项目中有个Global.a

  • [原创]开发辅助工具--Subversion安装、配置与使用(代码版本控制与操作)

    2009-4-11 2:52:00

    摘要: 在软件开发的过程中,经常因为程序代码版本的不统一而导致重新开发,或者在多人开发的项目中,多人共同修改了同一个公共代码文件而导致的相互复盖的问题,诸如此类的问题还有很多,下面我们就

  • 对WebForm实现Front Controller模式改进的构思

    2007-3-9 14:43:00

    摘要: 当使用了MonoRail后发现自己更偏向于使用Front Controllers模式,虽然这模式下缺少了Asp.net服务控件和基于事件驱动的功能,但是功能职责划分更细致明确;

  • DotNetNuke 7.0 Only Weeks Away!

    2012-11-16 1:45:00

    The software industry moves at a lightning pace, and it is only through constant focus and continuo