分析和提取的JSON属性 [英] Parse and Extract Attributes from JSON

查看:163
本文介绍了分析和提取的JSON属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的大的JSON文件:

  {
   数据:[
      {
         归属:空,
         标签:
            thenight2
         ]
         类型:形象,
         形象:{
            standard_resolution:{
               URL:http://distilleryimage3.s3.amazonaws.com/59d6984092a211e392db12e25f465f4f_8.jpg
               宽:640,
               高度:640
            }
         }
      },
      {
         归属:空,
         标签:
            thenight2
         ]
         类型:形象,
         形象:{
            low_resolution:{
               URL:http://distilleryimage1.s3.amazonaws.com/c179b34a91ff11e3b99c0aa73e1070c5_6.jpg
               宽:306,
               高度:306
            },
            缩略图:{
               URL:http://distilleryimage1.s3.amazonaws.com/c179b34a91ff11e3b99c0aa73e1070c5_5.jpg
               宽:150,
               高度:150
            },
            standard_resolution:{
               URL:http://distilleryimage1.s3.amazonaws.com/c179b34a91ff11e3b99c0aa73e1070c5_8.jpg
               宽:640,
               高度:640
            }
         },
         users_in_photo:[

         ]
      }
   ]
}
 

我想从所有的网​​址的名单中提取属性从的 standard_resolution 属性值的所有JSON的内部图像。怎样才能做到呢?

解决方案

我已经用在System.Web.Helpers命名空间的JSON类

(.NET 4.0)previously,它很适合我。您可以参考动态数组。它应同样采用这样的:

 动态myJson = Json.De code(myJsonString);
的foreach(在myJson.data.images.standard_resolution VAR URL){
//做一点事
}
 

I have a large JSON file similar to this:

{
   "data":[
      {
         "attribution":null,
         "tags":[
            "thenight2"
         ],
         "type":"image",
         "images":{
            "standard_resolution":{
               "url":"http://distilleryimage3.s3.amazonaws.com/59d6984092a211e392db12e25f465f4f_8.jpg",
               "width":640,
               "height":640
            }
         }
      },
      {
         "attribution":null,
         "tags":[
            "thenight2"
         ],
         "type":"image",
         "images":{
            "low_resolution":{
               "url":"http://distilleryimage1.s3.amazonaws.com/c179b34a91ff11e3b99c0aa73e1070c5_6.jpg",
               "width":306,
               "height":306
            },
            "thumbnail":{
               "url":"http://distilleryimage1.s3.amazonaws.com/c179b34a91ff11e3b99c0aa73e1070c5_5.jpg",
               "width":150,
               "height":150
            },
            "standard_resolution":{
               "url":"http://distilleryimage1.s3.amazonaws.com/c179b34a91ff11e3b99c0aa73e1070c5_8.jpg",
               "width":640,
               "height":640
            }
         },
         "users_in_photo":[

         ]
      }      
   ]
}

I want to extract from the a list of all the url attribute values from the standard_resolution attribute of all the images within the JSON. How can it be done?

解决方案

I have used the JSON class in System.Web.Helpers Namespace (.Net 4.0) previously and it works well for me. You are able to refer to arrays dynamically. It should be used similarly to this:

dynamic myJson = Json.Decode(myJsonString);
foreach (var url in myJson.data.images.standard_resolution){
//DO SOMETHING
}

这篇关于分析和提取的JSON属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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