正在加载···
AI摘要
HunYuan-Lite

本篇文章主要介绍了在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
//组成json字符串  

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);

C#解析、拼接json字符串

1
2
3
4
5
6
7
8
9
10
11
12
//解析json字符串
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());
}

C#解析、拼接json字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//JavaScript解析josn格式数据

string json="{"ret":{"xxx":"1"},"body":[{"aaa":"2","bbb":"3"},{"aaa":"2","bbb":"3"}]}";

var dataObj = eval("(" + json + ")");//转换为json对象

console.log(dataObj);

$.each(dataObj.rows, function (i, item)
{

console.log(item.ret);

})