好贷网好贷款

Newtonsoft.Json.dll使用

发布时间:2016-12-3 12:42:32 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"Newtonsoft.Json.dll使用",主要涉及到Newtonsoft.Json.dll使用方面的内容,对于Newtonsoft.Json.dll使用感兴趣的同学可以参考一下。

javascriptjsontextboxstringc 1:Newtonsoft.Json.dll 下载  http://json.codeplex.com/ 2:解析JSON字符窜 方法1: [csharp] view plaincopyprint? using Newtonsoft.Json;  using System.Text;    StringBuilder sb = new StringBuilder();                  string str = "[{ID:'1',Name:'John',Other:[{Age:'21',Sex:'0'}]},{ID:'2',Name:'Good',Other:[{Age:'36',Sex:'1'}]}]";                  JavaScriptArray javascript = (JavaScriptArray)JavaScriptConvert.DeserializeObject(str);                    for (int i = 0; i < javascript.Count; i++ )                  {                      JavaScriptObject obj = (JavaScriptObject)javascript[i];                      sb.Append("ID:" + obj["ID"].ToString());                      sb.Append("Name:" + obj["Name"].ToString());                      JavaScriptArray json = (JavaScriptArray)obj["Other"];                        for (int j = 0; j < json.Count; j++){                          JavaScriptObject jsonobj = (JavaScriptObject)json[j];                          sb.Append("Age:" + jsonobj["Age"].ToString());                          sb.Append("Sex:" + jsonobj["Sex"].ToString());                      }                  }   using Newtonsoft.Json; using System.Text; StringBuilder sb = new StringBuilder(); string str = "[{ID:'1',Name:'John',Other:[{Age:'21',Sex:'0'}]},{ID:'2',Name:'Good',Other:[{Age:'36',Sex:'1'}]}]"; JavaScriptArray javascript = (JavaScriptArray)JavaScriptConvert.DeserializeObject(str); for (int i = 0; i < javascript.Count; i++ ) { JavaScriptObject obj = (JavaScriptObject)javascript[i]; sb.Append("ID:" + obj["ID"].ToString()); sb.Append("Name:" + obj["Name"].ToString()); JavaScriptArray json = (JavaScriptArray)obj["Other"]; for (int j = 0; j < json.Count; j++){ JavaScriptObject jsonobj = (JavaScriptObject)json[j]; sb.Append("Age:" + jsonobj["Age"].ToString()); sb.Append("Sex:" + jsonobj["Sex"].ToString()); } } 方法2:不实用 [csharp] view plaincopyprint? string jsonText = "[{'a':'aaa','b':'bbb','c':'ccc'},{'a':'aaa2','b':'bbb2','c':'ccc2'}]";  JsonReader reader = new JsonReader(new StringReader(jsonText));                    while (reader.Read())                  {                     textBox1.Text += "TokenType = " + reader.TokenType + "   ValueType =  " + reader.ValueType + "   Value = " + reader.Value + "\r\n";                    }   string jsonText = "[{'a':'aaa','b':'bbb','c':'ccc'},{'a':'aaa2','b':'bbb2','c':'ccc2'}]"; JsonReader reader = new JsonReader(new StringReader(jsonText)); while (reader.Read()) { textBox1.Text += "TokenType = " + reader.TokenType + " ValueType = " + reader.ValueType + " Value = " + reader.Value + "\r\n"; }

上一篇:【代码】两个activity之间的互相的切换 数据不能同步的解决办法
下一篇:Android开发HTTP头部解释

相关文章

相关评论