2012-03-12 15:11
1:Newtonsoft.Json.dll 下载 http://json.codeplex.com/
2:解析JSON字符窜
方法1:
- usingNewtonsoft.Json;
- usingSystem.Text;
- StringBuildersb=newStringBuilder();
- stringstr="[{ID:'1',Name:'John',Other:[{Age:'21',Sex:'0'}]},{ID:'2',Name:'Good',Other:[{Age:'36',Sex:'1'}]}]";
- JavaScriptArrayjavascript=(JavaScriptArray)JavaScriptConvert.DeserializeObject(str);
- for(inti=0;i<javascript.Count;i++)
- {
- JavaScriptObjectobj=(JavaScriptObject)javascript[i];
- sb.Append("ID:"+obj["ID"].ToString());
- sb.Append("Name:"+obj["Name"].ToString());
- JavaScriptArrayjson=(JavaScriptArray)obj["Other"];
- for(intj=0;j<json.Count;j++){
- JavaScriptObjectjsonobj=(JavaScriptObject)json[j];
- sb.Append("Age:"+jsonobj["Age"].ToString());
- sb.Append("Sex:"+jsonobj["Sex"].ToString());
- }
- }
- stringjsonText="[{'a':'aaa','b':'bbb','c':'ccc'},{'a':'aaa2','b':'bbb2','c':'ccc2'}]";
- JsonReaderreader=newJsonReader(newStringReader(jsonText));
- while(reader.Read())
- {
- textBox1.Text+="TokenType="+reader.TokenType+"ValueType="+reader.ValueType+"Value="+reader.Value+"\r\n";
- }