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 青蛙學堂 阅读(2310) 评论(0)  编辑 收藏 引用 所属分类: c#

只有注册用户登录后才能发表评论。
<2012年3月>
26272829123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

常用链接

留言簿(8)

随笔分类

随笔档案

收藏夹

青蛙学堂

最新评论

阅读排行榜

评论排行榜