本文介绍了如何解析使用的JSONObject这种反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的反应,我回去形式的服务器。我想分析它,并获得hospital_name出来。我会怎么做呢?
[
{
医院:{
ID:63083,
hospital_name:科罗拉多州精神健康研究所,
hospital_add_1:1600W,24日ST,
hospital_add_2:空,
hospital_city:普韦布洛号,
hospital_state:CO,
hospital_zip:81003,
hospital_phone:719-546-4000 \\ R,
hospital_fax:空,
hospital_description:空,
callcenter_agent_approval:0,
hospital_site:,
mdpocket_approval:0,
脸谱:
},
楼:[],
部: [],
图片: [],
注意事项:[]
},
{
医院:{
ID:63084,
hospital_name:阳明山庄医学中心,
hospital_add_1:400瓦16街
hospital_add_2:空,
hospital_city:普韦布洛号,
hospital_state:CO,
hospital_zip:81003,
hospital_phone:719-584-4000 \\ R,
hospital_fax:空,
hospital_description:空,
callcenter_agent_approval:0,
hospital_site:,
mdpocket_approval:0,
脸谱:
},
楼:[],
部: [],
图片: [],
注意事项:[]
},
{
医院:{
ID:63085,
hospital_name:圣玛丽 - 考文医学中心,
hospital_add_1:1008 Minnequa大道
hospital_add_2:空,
hospital_city:普韦布洛号,
hospital_state:CO,
hospital_zip:81004,
hospital_phone:719-560-4000 \\ R,
hospital_fax:空,
hospital_description:空,
callcenter_agent_approval:0,
hospital_site:,
mdpocket_approval:0,
脸谱:
},
楼:[],
部: [],
图片: [],
注意事项:[]
}
]
编辑的JSON
*的已更新JSON * 的
解决方案
[// JSON数组节点
{// JSON对象节点
医院:{// json对象医院
要解析
JSONArray JR =新JSONArray(jsonstring);
的for(int i = 0; I< jr.length();我++)
{
JB的JSONObject =(JSONObject的)jr.getJSONObject(I)
JSONObject的JB1 =(JSONObject的)jb.getJSONObject(医院);
字符串名称= jb1.getString(hospital_name);
Log.i(名......,名);
}
登录
3月2日至十八日:09:43.950:I /名称....(951):科罗拉多州精神健康研究所
3月二日至18日:09:43.950:I /名称....(951):阳明山庄医疗中心
3月二日至18日:09:43.950:I /名称....(951):圣玛丽 - 考文医学中心
I have this response that I get back form server. I want to parse it and get the hospital_name out of it. How would I go about it?
[
{
"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": []
}
]
EDITED THE JSON*UPDATED JSON *
解决方案
[ // json array node
{ // json object node
"Hospital": { // json object Hospital
To parse
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);
}
Log
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
这篇关于如何解析使用的JSONObject这种反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!