1、c# 通过JObject解析json对象
json数据
{
"code": 200,
"message": "获取配置的中间件信息",
"data": [
{
"nodeId": "17001",
"nodeHost": "3",
"nodePort": 17001,
"nodeType": 1,
"linkType": 0,
"status": true,
"syncTime": 1604364540191
},
{
"nodeId": "17002",
"nodeHost": "3",
"nodePort": 17002,
"nodeType": 1,
"linkType": 0,
"status": true,
"syncTime": 1604361560866
}
]
}
获取json单个元素,如nodeId
JObject jo = JObject.Parse(json);
string code = jo.Value<string>("code");
string msg = jo.Value<string>("msg");
JArray data = jo.Value<JArray>("data");
if (code == "200")
{
foreach(var node in data)
{
node["nodeId"].ToString()
}