c# JArray提取JSON格式数组获取指定字段元素数据

Newtonsoft.Json.dll

 if (retString.Contains("boxid"))
                {
                    dynamic jsonStr = JsonConvert.DeserializeObject<dynamic>(retString);
                    //  jsonStr["data"]["lblList"][0]["lblno"] = $"{where_name}";
                    JArray array2  = jsonStr["data"]["lblList"];
                    //      string output = JsonConvert.SerializeObject(jsonStr2, Newtonsoft.Json.Formatting.Indented);
                    //      JArray array = (JArray)JsonConvert.DeserializeObject(output);

                    dynamic jsonStr2 = array2[0];
                    //string output = JsonConvert.SerializeObject(jsonStr2, Newtonsoft.Json.Formatting.Indented);
                    string aa = jsonStr2["lblno"];

                }

retString原始数据

{
  "code": 1,
  "data": {
    "lblList": [
      {
        "boxid": "10180129LES8553567",
        "creator": "AG2952",
        "ctime": "2018-01-29 14:28:39",
        "id": "39805809",
        "iscopy": null,
        "layer": "0",
        "lblno": "1898622",
        "lot": "SLA18036148",
        "packruleid": "PR-007",
        "ptimes": null,
        "qty": "10000",
        "rpoper": null,
        "rptime": null,
        "seqno": "002"
      },

      {
        "boxid": "10180129LES8553570",
        "creator": "AG2952",
        "ctime": "2018-01-29 14:28:39",
        "id": "39805812",
        "iscopy": null,
        "layer": "0",
        "lblno": "1898625",
        "lot": "SLA18036148",
        "packruleid": "PR-007",
        "ptimes": null,
        "qty": "10000",
        "rpoper": null,
        "rptime": null,
        "seqno": "005"
      },
  
      {
        "boxid": "20180129LES8553566",
        "creator": "AG2952",
        "ctime": "2018-01-29 14:28:39",
        "id": "40052739",
        "iscopy": null,
        "layer": "0",
        "lblno": "1898621",
        "lot": "SLA18036148",
        "packruleid": "PR-007",
        "ptimes": null,
        "qty": "10000",
        "rpoper": null,
        "rptime": null,
        "seqno": "001"
      }
    ],
    "lotId": "SLA18036148"
  },
  "message": "成功"
}
欢迎讨论,相互学习。 txwtech@163.com
原文地址:https://www.cnblogs.com/txwtech/p/15766283.html