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": "成功"
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM