简体   繁体   中英

How to get value from JSON Array Plss

[  
   {  
      "mcClaimModelInfoId":{  
         "claim_no":"1019",
         "sno":1,
         "policy_no":"STC1001674000100"
      },
      "model_type":"1",
      "vehicle_count":"100",
      "remarks":"null",
      "status":"null",
      "entry_date":null
   },
   {  
      "mcClaimModelInfoId":{  
         "claim_no":"1019",
         "sno":2,
         "policy_no":"STC1001674000100"
      },
      "model_type":"1",
      "vehicle_count":"10",
      "remarks":"null",
      "status":"null",
      "entry_date":null
   },
   {  
      "mcClaimModelInfoId":{  
         "claim_no":"1019",
         "sno":3,
         "policy_no":"STC1001674000100"
      },
      "model_type":"8",
      "vehicle_count":"5454",
      "remarks":"null",
      "status":"null",
      "entry_date":null
   }
]

An example in python:

import json
def test():
    model = ''' [{"mcClaimModelInfoId":{"claim_no":"1019","sno":1,"policy_no":"STC1001674000100"},"model_type":"1","vehicle_count":"100","remarks":"null","status":"null","entry_date":null}] '''
return json.loads(model)


test_one = test()
for m in test_one:
   print(m['mcClaimModelInfoId])

here is an example of how to do it in python, you are iterating through the json. You can do the same thing in Java or any other language.

json_line = line['mcClaimModelInfoId']['claim_no'] => 1019 (example)

Well since that what you are showing its just an array, and if... You want an example of access and iterate in c# here you have a simple way to do it:

using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

JObject objTemp = JObject.Parse(yourJSON); //Converts the JSON to a JObject
JArray arr = JArray.Parse(objTemp["ArrayName"].ToString());
foreach (var arrElement in arr)
{
     var x = (string)arrElement["mcClaimModelInfoId"]["model_type"];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM