如何从JSON数组中获取价值

时间:2019-03-27 09:26:37

标签: java json pls

[  
   {  
      "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
   }
]

2 个答案:

答案 0 :(得分:0)

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])

这是一个如何在python中进行操作的示例,您正在遍历json。 您可以使用Java或任何其他语言执行相同的操作。

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

答案 1 :(得分:0)

好吧,既然如此,您所显示的只是一个数组,如果...您想要在c#中进行访问和迭代的示例,这里有一种简单的方法:

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"];
}