JSON嵌套参数 [英] Json nested parameters

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

问题描述

我使用的JSON对象的数据来填充列表视图。该对象具有以下参数:

I am using data from a Json object to populate a list view. The object has these parameters:

"id": "339150749455906", 
"posts": {
"data": [
{
"id": "339150749455906_545370565500589", 
"from": {
  "category": "Food/beverages", 
  "name": "Pepsi", 
  "id": "339150749455906"
}, 
"story": "Pepsi updated their cover photo.", 
"picture": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash3/942740_545370555500590_46289134_s.jpg", 
"link": "http://www.facebook.com/photo.php?fbid=545370555500590&set=a.365573920146922.72816.339150749455906&type=1&relevant_count=1", 
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif", 
"actions": [
  {
    "name": "Comment", 
    "link": "http://www.facebook.com/339150749455906/posts/545370565500589"
  }, 
  {
    "name": "Like", 
    "link": "http://www.facebook.com/339150749455906/posts/545370565500589"
  }
], 

我要访问的里面的参数/键动作链接。到目前为止,我使用的:

I want to access the link inside the parameter/key "actions". So far I am using:

foreach (var post in postsTaskResult.posts.data)
{
   link = new Uri(string.Format("{0}", (string)post["link"])); 
}



不过,这只是带来了数据的链接。如何访问其他链接?

However, this only brings the link in the "data". How can I access the other 'link' ?

推荐答案

试试这个。

var actionLinks = new List<string>();
var actions = post["actions"] as JArray; // if this works then all is well
foreach(var item in actions)
{
    actionLinks.Add((string)item["link"]);
}



我想你也可以使用一些花哨的LINQ与此类似。

I think you can also use some fancy Linq with this like

var actionLinks = ((JArray)post["actions"])
         .Children<JObject>()
         .Select(a => (string)a["link"])
         .ToList();



非常不测试。只是让我知道。

Very un-tested. Just let me know.

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

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