当前位置 > 首页 > 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.



  • 分解分析树,KPIs

    2007-1-24 16:29:00

    摘要: 1. 利用分解分析树,针对某个指标,简单清晰的分析多维数据。 2. 用户首要关心的关键性能指标KPIs。 阅读全文 anchky 2007-01-24 14:52 发表评论

  • 聪明的苹果——iPhone 3GS。

    2009-7-8 21:43:00

    音乐手机、照相手机、GPS手机。音乐上,更大的内存;照相上,镜头的像素、镜头的专业度、自拍镜;GPS定位上,等等等等。在我的记忆中,从来没有一款手机以速度作为卖点来宣传过。你的记忆中有吗? 3

  • ORM映射框架总结--数据库操作库(精修版)

    2010-4-20 7:38:00

    阅读: 190 评论: 5 作者: 贺臣 发表于 2010-04-19 23:03 原文链接 1. ORM 数据库操作原理 前面已经介绍过了个人

  • Custom loading screen on Monotouch

    2009-11-16 7:49:00

    I had a request from my previous post about the DoneDone app to give a little insight on how the

  • Generating PDFs in ASP.NET Pages – PDF Duo .Net

    2009-9-3 0:49:00

    In my current contract, I need to generate database-driven PDFs on the fly. I’ve done the first pro

  • Visual Studio anpassen und erweitern - in Paderborn

    2007-3-27 16:05:00

    Mein Kollege Jens Schaller und ich sind am 2. April 2007 bei der .NET User Group Paderborn zu B

  • 别在领域模型迷失了自己

    2007-9-28 12:06:00

    摘要: 本不想对这个图书馆再掀话题﹐看了亚同志的重构图书馆惊魂夜﹐觉得还是有必要完整地解释一下图书馆与领域模型﹐毕竟这个问题由我而起﹐善终一下吧 阅读全文 小生 2007-09-28 1

  • Asp.net控件开发学习笔记(七)----WebControl基类

    2009-10-10 17:04:00

    摘要: WebControl基类 在Asp.net控件开发中,WebControl基类给我们提供了对于控件的Style更加灵活的解决方案,因为在System.Web.UI.Control基类中只能手

  • How to download the CAT.NET 2.0?

    2011-7-20 16:09:00

    How to download the CAT.NET 2.0?

  • NET下RabbitMQ实践[配置篇]

    2010-10-21 14:56:00

    这个系列目前计划写四篇,分别是配置,示例,WCF发布,实战。当然不排除加餐情况。 介绍: rabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统。他遵循M