gpt4 book ai didi

java - 如何使用 JSONObject 解析此响应

转载 作者:行者123 更新时间:2023-12-01 08:05:43 25 4
gpt4 key购买 nike

我收到了从服务器返回的响应。我想解析它并从中获取 Hospital_name 。我该怎么办?

[
{
"Hospital": {
"id": "63083",
"hospital_name": "Colorado Mental Health Inst",
"hospital_add_1": "1600 W 24th St",
"hospital_add_2": null,
"hospital_city": "Pueblo",
"hospital_state": "CO",
"hospital_zip": "81003",
"hospital_phone": "719-546-4000\r",
"hospital_fax": null,
"hospital_description": null,
"callcenter_agent_approval": "0",
"hospital_site": "",
"mdpocket_approval": "0",
"facebook": ""
},
"Floor": [],
"Department": [],
"Image": [],
"Notes": []
},
{
"Hospital": {
"id": "63084",
"hospital_name": "Parkview Medical Center",
"hospital_add_1": "400 W 16th St",
"hospital_add_2": null,
"hospital_city": "Pueblo",
"hospital_state": "CO",
"hospital_zip": "81003",
"hospital_phone": "719-584-4000\r",
"hospital_fax": null,
"hospital_description": null,
"callcenter_agent_approval": "0",
"hospital_site": "",
"mdpocket_approval": "0",
"facebook": ""
},
"Floor": [],
"Department": [],
"Image": [],
"Notes": []
},
{
"Hospital": {
"id": "63085",
"hospital_name": "St Mary-Corwin Medical Center",
"hospital_add_1": "1008 Minnequa Ave",
"hospital_add_2": null,
"hospital_city": "Pueblo",
"hospital_state": "CO",
"hospital_zip": "81004",
"hospital_phone": "719-560-4000\r",
"hospital_fax": null,
"hospital_description": null,
"callcenter_agent_approval": "0",
"hospital_site": "",
"mdpocket_approval": "0",
"facebook": ""
},
"Floor": [],
"Department": [],
"Image": [],
"Notes": []
}
]

编辑 JSON*更新 JSON *

最佳答案

[ // json array node 
{ // json object node
"Hospital": { // json object Hospital

解析

JSONArray jr = new JSONArray("jsonstring");
for(int i=0;i<jr.length();i++)
{
JSONObject jb = (JSONObject)jr.getJSONObject(i);
JSONObject jb1 =(JSONObject) jb.getJSONObject("Hospital");
String name = jb1.getString("hospital_name");
Log.i("name....",name);
}

日志

02-18 03:09:43.950: I/name....(951): Colorado Mental Health Inst
02-18 03:09:43.950: I/name....(951): Parkview Medical Center
02-18 03:09:43.950: I/name....(951): St Mary-Corwin Medical Center

关于java - 如何使用 JSONObject 解析此响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21846806/

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