public static void Readjson()
{
string jsonfile = "D://tsconfig1.json";
using (System.IO.StreamReader file = System.IO.File.OpenText(jsonfile))
{
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject o = (JObject)JToken.ReadFrom(reader);
string a = o["lotname"].ToString();
var b = o["other"];
var c = b["lotaddress"];
var d = o["devices"];
foreach(JObject e in d)
{
var deviceID = e["deviceID"];
var name = e["name"];
var IP = e["IP"];
}
}
}
}
tsconfig1.json文件内容
{
"lotname": "停车系统",
"devices": [
{
"deviceID": "EI1001",
"name": "东道进口相机",
"type": "进口",
"IP": "192.168.1.100"
},
{
"deviceID": "EI1002",
"name": "东道进口语音屏",
"type": "进口",
"IP": "192.168.1.102"
},
{
"deviceID": "EO1003",
"name": "东道出口相机",
"type": "出口",
"IP": "192.168.1.103"
},
{
"deviceID": "EO1004",
"name": "东道出口语音屏",
"type": "出口",
"IP": "192.168.1.104"
}
],
"other": { "lotname": "wz001", "lotaddress": "wenzhou" }
}
注意:记事本另存为 以上内容时编码选择 U-TF8
原文地址:https://www.cnblogs.com/hbgjh/p/9176773.html