c# 通過JObject解析json物件
阿新 • • 發佈:2022-12-07
單層級
{ "input": { "size": 193156, "type": "image/png" }, "output": { "size": 59646, "type": "image/png", "width": 487, "height": 284, "ratio": 0.3088, "url": "https://api.xxxxxx.com/output/hrqtghqtv0ab4qgv.png" } }
獲取
Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(jsonText);
jobject["input"]["size"]
多層級
{ "status":200, "msg": "查詢完畢", "data": [ { "code": 193156, "source": "AAA", "data":[ { "Plant":"2812", "PartNo":"666666", "PartType":"PCB" } ] }, {"code": 193157, "source": "BBB", "data":[ { "VIDEO":"AV" }, { "WORD":"WPS" } ] } ] }
JObject xxx = JObject.Parse(JsonText);
PartType = xxx["data"][0]["data"][0]["PartType"].ToString(); // PCB