雖然我已經想出瞭如何使用Newtonsoft來讀取JSON文件,但並不知道如何閱讀這些要點。我想閱讀所有X,Y點。什麼是最好的方法來做到這一點?我有整個JSON文件「讀」,我現在如何得到個人點?C#Json.Net讀取數據
這是從JSON文件小摘錄:
{
"Points": [
{
"X": -3.05154,
"Y": 4.09
},
{
"X": -3.05154,
"Y": 3.977
}
],
"Rectangles": [
{
"XMin": -3.08154,
"XMax": 3.08154,
"YMin": -4.5335,
"YMax": 4.5335
}
]
}
JObject o1 = JObject.Parse(File.ReadAllText(@"C:\Users\user\Desktop\test.json"));
Koordinaten kor = new Koordinaten();
// read JSON directly from a file
using (StreamReader file = File.OpenText(@"C:\Users\user\Desktop\test.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject o2 = (JObject)JToken.ReadFrom(reader);
}
您可以嘗試將JSON反序列化爲「真實」類而不是JObject – Icepickle