访问嵌套的JSON数据 [英] Accessing nested JSON data

查看:100
本文介绍了访问嵌套的JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一些来自第三方网络服务的JSON数据,如下所示:



{

" title":" item of items",
" owner":" Andrew",$
" updated" ;:1302896577,

" items" ;: [

{

" title":" This is the Title 1",

" content" ;: {

" id":" 1",$
" content":" Details 1 ..."

" author":" Andy",$
},

{

" title":" This is the Title 2" ;,

" content":{

" id":" 2",$
" content":" Details 2 .. 。"

" author":" Andy",

},

...



我有一个对象,我想选择项目数据如下:




 


public



 



 




class
MyItem


 


 




{


 


 




 


public
string 作者;


 


 



 




public
string 标题;


 


 



 




public
string 内容;

}



我正在尝试使用此代码,但我无法阅读我正在使用JSON.NET来处理数据。



 


 



 


 


 



 


JObject jobj =
JObject 。解析(内容);


 



  ;




JArray subscriptions =( JArray )jobj [ " items" ];


 


 



 






IEnumerable
< MyItem >
items =


 


 



 




来自 f
in 订阅


 


 



 




选择
new
MyItem ()


 


 


{


   Title =(



 




string )f [ " title" ],


 


 


 作者=(



 




string )f [ " author" ],


 


 


  Content = ???


 



 




};


 


 


 




 


 




有什么想法吗?



先谢谢。



Andrew

解决方案

本教程可能会帮助您解析JSON,本教程还有一些可以帮助您完成此任务的链接,


http:// saad-mehmood。 blogspot.com/2013/08/parsing-json-in-windows-phone.html



问候,


Hi,

I have some JSON data coming back from a 3rd party webservice which looks like this:

{
"title": "List of items",
"owner": "Andrew",
"updated": 1302896577,
"items": [
{
"title": "This is the Title 1",
"content": {
"id": "1",
"content": "Details 1..."
"author": "Andy",
},
{
"title": "This is the Title 2",
"content": {
"id": "2",
"content": "Details 2..."
"author": "Andy",
},
...

I have an object that I would like to select the item data into as follows:

 

public

 

 

class MyItem

 

 

{

 

 

 

public string Author;

 

 

 

public string Title;

 

 

 

public string Content;
}

I am trying to use this code but I have not been able to read the content/content field (or the id field). I am using JSON.NET to process the data.

 

 

 

 

 

 

JObject jobj = JObject.Parse(content);

 

 

JArray subscriptions = (JArray)jobj["items"];

 

 

 


IEnumerable
<MyItem> items =

 

 

 

from f in subscriptions

 

 

 

select new MyItem()

 

 

{

  Title = (

 

string)f["title"],

 

 

  Author = (

 

string)f["author"],

 

 

  Content = ???

 

 

};

 

 

 

 

 


Any ideas?

Thanks in advance.

Andrew

解决方案

Hi, Well this tutorial might help you out in parsing JSON, this tutorial also has some links that would help you doing it,

http://saad-mehmood.blogspot.com/2013/08/parsing-json-in-windows-phone.html

Regards,


这篇关于访问嵌套的JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆