博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
json parese
阅读量:6602 次
发布时间:2019-06-24

本文共 2662 字,大约阅读时间需要 8 分钟。

private void button5_Click(object sender, EventArgs e)        

{           

  //string dd=System.Guid.NewGuid().ToString("N");            

//[{"aqi":60,"area":"\u5317\u4eac","pm2_5":3,"pm2_5_24h":43,"position_name":"\u4e07\u5bff\u897f\u5bab","primary_pollutant":"\u9897\u7c92\u7269(PM2.5)","quality":"\u826f","station_code":"1001A","time_point":"2013-05-29T09:00:00Z"}]             var json = HandlerResponse("=北京&token=5j1znBVAsnSf5xQyNQyq", "GET");                        

//var jsonReader = new JsonTextReader(new StringReader(json));             //var jArray = (JArray)new JsonSerializer().Deserialize(jsonReader);            

var jObject = (JObject)new JsonSerializer().Deserialize(jsonReader);对应//{"aqi":60,"area":"\u5317\u4eac","pm2_5":3,"pm2_5_24h":43,"position_name":"\u4e07\u5bff\u897f\u5bab","primary_pollutant":"\u9897\u7c92\u7269(PM2.5)","quality":"\u826f","station_code":"1001A","time_point":"2013-05-29T09:00:00Z"}                         //foreach (var dr in jArray)             //{             //    var jObject = jArray[0];             //    var aqi = (int)dr["aqi"];             //    var area = (string)dr["area"];             //    var pm2_5 = (int)dr["pm2_5"];             //    var pm2_5_24h = (int)dr["pm2_5_24h"];             //}

            //方法二             //var jArray = JsonConvert.DeserializeObject<JArray>(json);             //foreach (JObject obj in jArray.Values<JObject>())             //{             //    var aqi = (int)obj["aqi"];                             //}

            //方法三             var jArray = JArray.Parse(json);             foreach (JObject obj in jArray)             {                 var aqi = obj["aqi"].Value<int>();                             }         }

        //public static JObject ReadJson(this RequestContext context)         //{         //    using (var streamReader = new StreamReader(context.InputStream, context.GetEncoding()))         //    using (var jsonReader = new JsonTextReader(streamReader))         //        return JObject.Load(jsonReader);         //}

        //public static T ReadJson<T>(this RequestContext context)         //{         //    using (var streamReader = new StreamReader(context.InputStream, context.GetEncoding()))         //    using (var jsonReader = new JsonTextReader(streamReader))         //        return (T)new JsonSerializer().Deserialize(jsonReader, typeof(T));         //}

        //public static object ReadJsonObject(this RequestContext context)         //{         //    using (var streamReader = new StreamReader(context.InputStream, context.GetEncoding()))         //    using (var jsonReader = new JsonTextReader(streamReader))         //        return new JsonSerializer().Deserialize(jsonReader);         //}

        //public static JArray ReadJsonArray(this RequestContext context)         //{         //    using (var streamReader = new StreamReader(context.InputStream, context.GetEncoding()))         //    using (var jsonReader = new JsonTextReader(streamReader))         //        return JArray.Load(jsonReader);         //}

        //public static string ReadString(this RequestContext context)         //{         //    using (var streamReader = new StreamReader(context.InputStream, context.GetEncoding()))         //        return streamReader.ReadToEnd();         //}

转载于:https://www.cnblogs.com/fx2008/archive/2013/05/29/3105602.html

你可能感兴趣的文章
修改mysql数据库编码
查看>>
代码审查RhodeCode试用
查看>>
我的友情链接
查看>>
squid代理服务器的控制功能详细配置
查看>>
MongoDB权威指南——入门
查看>>
mybatis设置一对多映射
查看>>
ubuntu 14.04编译安装openvas 8
查看>>
阳性水草与阴性水草的区分
查看>>
DIV+css命名规则
查看>>
Zookeeper 注册中心安装
查看>>
十一、RDS VDI 标准部署
查看>>
String StringBuffer StringBuilder
查看>>
通过路由器静态PAT访问FTP服务器测试
查看>>
自己需要读的书
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
LVS/DR + keepalived负载均衡高可用实现
查看>>
我的友情链接
查看>>
notification
查看>>
4.1 Android如何访问资源
查看>>