本篇文章主要介绍了在C#中json字符串的拼接与解析的实操案例,希望你阅读完后,对你有所帮助。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| JObject ret = new JObject(); ret["xxx"] = "1"; JArray body = new JArray(); JObject obj = new JObject(); obj["aaa"] = "2"; obj["bbb"] = "3"; body.Add(obj); body.Add(obj); JObject sss = new JObject(); sss["ret"] = ret; sss["body"] = body; string aaaa = JsonConvert.SerializeObject(sss);
Information.LogError(aaaa);
|

1 2 3 4 5 6 7 8 9 10 11 12
| JObject jo = (JObject)JsonConvert.DeserializeObject(aaaa); string qaz = jo["ret"].ToString(); string ws = jo["body"].ToString(); Information.LogError(qaz); Information.LogError(ws); JArray xxs = (JArray)JsonConvert.DeserializeObject(ws); for(int i =0; i<xxs.Count;i++) { Information.LogError(xxs[i]["aaa"].ToString()); Information.LogError(xxs[i]["bbb"].ToString()); }
|

1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
string json="{"ret":{"xxx":"1"},"body":[{"aaa":"2","bbb":"3"},{"aaa":"2","bbb":"3"}]}";
var dataObj = eval("(" + json + ")"); console.log(dataObj);
$.each(dataObj.rows, function (i, item) {
console.log(item.ret);
})
|