C# NEWTONSOFT.JSON读取json文件

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

posted on 2020-05-15 13:16 青蛙學堂 阅读(2307) 评论(0)  编辑 收藏 引用 所属分类: c#

只有注册用户登录后才能发表评论。
<2006年7月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

导航

统计

常用链接

留言簿(8)

随笔分类

随笔档案

收藏夹

青蛙学堂

最新评论

阅读排行榜

评论排行榜