zoukankan      html  css  js  c++  java
  • json parese

    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("http://www.pm25.in/api/querys/pm2_5.json?city=北京&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();         //}

  • 相关阅读:
    RP2833 FPGA对应串口标识
    rp2833 网卡以及串口与接插件位置关系
    环境检测 短信收发的测试
    #A号板测试汇总
    #8号板测试汇总
    #2号板测试汇总
    #6号板问题
    【POJ3045】Cow Acrobats(贪心)
    【HDU1219】AC Me(水题)
    BUPT2017 wintertraining(15) #2 题解
  • 原文地址:https://www.cnblogs.com/fx2008/p/3105602.html
Copyright © 2011-2022 走看看