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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM