json格式数
[{ "id": 11162, "docentry": 3293, "pmid": 31173, "ItemCode": "UBAC11211OF-A54", "basicName_bg": "男女式涤纶挎包", "taxDate": "2018-07-24 10:37:20" }, { "id": 11163, "docentry": 3293, "pmid": 31279, "ItemCode": "UBAC11711OF-A54", "basicName_bg": "男女式收纳袋", "taxDate": "2018-07-24 10:37:20" }, { "id": 11164, "docentry": 3293, "pmid": 31440, "ItemCode": "UBAC05811OF-A40", "basicName_bg": "男女式涤纶背包", "taxDate": "2018-07-24 10:37:20" }]
用JArray
JArray aa = JArray.Parse(json); for (int i = 0; i < aa.Count; i++) { string docentry = aa[i]["id"].ToString(); }
还有一种方法是拼接json
{ "d": [{ "id": 11162, "docentry": 3293, "pmid": 31173, "ItemCode": "UBAC11211OF-A54", "basicName_bg": "男女式涤纶挎包", "taxDate": "2018-07-24 10:37:20" }, { "id": 11163, "docentry": 3293, "pmid": 31279, "ItemCode": "UBAC11711OF-A54", "basicName_bg": "男女式收纳袋", "taxDate": "2018-07-24 10:37:20" }, { "id": 11164, "docentry": 3293, "pmid": 31440, "ItemCode": "UBAC05811OF-A40", "basicName_bg": "男女式涤纶背包", "taxDate": "2018-07-24 10:37:20" }] }
JObject jsonObj = new JObject(); string json = context.Request["data"]; string json_str = "{"d":" + json + "}"; jsonObj = JObject.Parse(json_str); foreach (var item in jsonObj["d"]) { string docentry = item["id"].ToString(); } JArray aa = JArray.Parse(json); for (int i = 0; i < aa.Count; i++) { string docentry = aa[i]["id"].ToString(); }