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 File Contents
{
"Lotname": "Parking System",
"Devices": [
{
"DeviceID": "EI1001",
"Name": "Host imported Camera",
"Type": "Import",
"IP": "192.168.1.100"
},
{
"DeviceID": "EI1002",
"Name": "Host import voice screen",
"Type": "Import",
"IP": "192.168.1.102"
},
{
"DeviceID": "EO1003",
"Name": "Host Exit Camera",
"Type": "Exit",
"IP": "192.168.1.103"
},
{
"DeviceID": "EO1004",
"Name": "Host export voice screen",
"Type": "Exit",
"IP": "192.168.1.104"
}
],
"Other": {"Lotname": "wz001", "lotaddress": "Wenzhou"}
}
Note: When Notepad is saved as above, the encoding is selected U-tf8
C # Newtonsoft. JSON read JSON file