c# 通过JObject解析json对象

 

单层级

{
   "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

 

posted @ 2022-12-07 15:30  qingjiawen  阅读(399)  评论(0编辑  收藏  举报