gpt4 book ai didi

java - 如何使用java中的键获取Json值?

转载 作者:行者123 更新时间:2023-12-02 00:08:00 27 4
gpt4 key购买 nike

我有如下所示的 JSON 数组。如何根据其键获取值?

$> 

[{Work
> Group=[{"id":"wNUvBiv5tQDFphP3zITN5NDEqyXJM8W2","errRsn":["Response
> time from Sweden exceeded 1500 ms."],"ap":"100.0
> %","status":"Trouble","name":"xxxx","rsptime":"1549
> ms","downs":"0","tDwn":"5 Hrs 50 Mins
> ","conf":"no","mtype":"URL","monitorid":"2c2d1ba5b57d9c1be8fcae5522b5bb9f","lsDur":"-","lsDwn":""},{"id":"wNUvBiv5tQB1kKQSZBij\/b8FU++kkoRh","ap":"100.0
> %","status":"Up","name":"xxx","rsptime":"424
> ms","downs":"0","conf":"no","mtype":"HOMEPAGE","monitorid":"58e79381158d85e8eb944ec5506db09a","lsDur":"-"},{"id":"wNUvBiv5tQD\/DIkhHWufnTRJzbcIgZk4","rspvalue":"-","downReason":"Unknown
> Host","status":"Down","name":"xxxx","tDwn":"62 days 17 Hrs 7 Mins
> ","conf":"yes","mtype":"PORT","monitorid":"6cacfbf47ad21d824006be1168efc3c6","lsDwn":"2012-09-18"},{"id":"wNUvBiv5tQCBw1RAuk0Q2P1FZPxXxMr1","downReason":"Trouble"

天 0 小时 0 分钟 ","lsDwn":"2012-06-21"}]}]

最佳答案

使用以下代码解析您的 json 字符串:

JSONArray jarray = new JSONArray("Your JSON String Here");

for (int i=0; i < jarray.length(); i++)
{
JSONObject oneObject = jArray.getJSONObject(i);
// Pulling items from the array
String oneObjectsid = oneObject.getString("id");
String oneObjectsap = oneObject.getString("ap");
String oneObjectsstatus = oneObject.getString("status");
String oneObjectsname = oneObject.getString("name");
//your rest code here...
}

关于java - 如何使用java中的键获取Json值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13467595/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com