{"retcode":0,"result":[{"poll_type":"message","value":{"msg_id":32065,"from_uin":2246865592,"to_uin":1589188359,"msg_id2":605408,"msg_type":9,"reply_ip":178848417,"time":1352614319,"content":[["font",{"size":10,"color":"000000","style":[0,0,0],"name":"\u9ED1\u4F53"}],"hi"]}}]}请问如何用Newtonsoft.Json或其他类库取出hi这个值,感激不尽!
2 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingNewtonsoft.Json;usingNewtonsoft.Json.Converters;usingNewtonsoft.Json.Serialization;usingNewtonsoft.Json.Linq;namespacecscliTest{publicclassFont{publicintsize;publicintcolor;publicstringname;publicListstyle=newList (); }publicclassContent{publicstringhi;publicFontfont=newFont();}publicclassValue{publicintmsg_id;publicuintfrom_uin;publicuintto_uin;publicintmsg_id2;publicintmsg_type;publicintreply_ip;publicinttime;publicListcontent=newList (); }publicclassResult{publicstringpoll_type;publicValuevalue;}publicclasssss{publicintretcode;publicListresult=newList (); }publicclassTest{publicintm_a;publicinta{get;set;}}classProgram{staticvoidMain(string[]args){//测试数据sssa=newsss();a.retcode=0;Resultr=newResult();Valuev=newValue();Contentc=newContent();Fontf=newFont();f.size=10;f.color=0;f.style=newList(newint[]{0,0,0}); f.name="xxx";c.font=f;c.hi="hello";v.msg_id=32065;v.from_uin=2246865592;v.to_uin=1589188359;v.msg_id2=605408;v.msg_type=9;v.reply_ip=178848417;v.time=1352614319;v.content.Add(c);r.value=v;a.result.Add(r);stringxx=JsonConvert.SerializeObject(a);Console.WriteLine(xx);//方法一(需定义上面那些类)sssa2=(sss)JsonConvert.DeserializeObject(xx); Console.WriteLine(a2.retcode);//方法二(不需定义上面那些类)JObjecto=(JObject)JsonConvert.DeserializeObject(xx);JTokeno2=o["result"][0];JTokeno3=o2["value"];JTokeno4=o3["content"][0];JTokeno5=o4["hi"];Console.WriteLine(o5.ToString());}}}感觉content后面的两个[[格式有问题,所以我这里的和你的格式有点差别,请注意。以前做过,今天翻了下,网上的太乱,以至于弄了挺久。
拉莫斯之舞
TA贡献1820条经验 获得超10个赞
varser=newJavaScriptSerializer();returnser.Deserialize(json);JavaScriptSerializer类在System.Web.Script.Serialization需引入System.Web.Extensionsdll
添加回答
举报
0/150
提交
取消