2014-06-12 35 views
1

我向服务器发送请求,它给了我一个响应并以JSON格式提供数据,现在我想从该JSON格式中获取某些特定值,这么做太热了。从android中获取JSON的值

{ 
"education": [ 
{ 
    "school": { 
    "id": "2009305", 
    "name": "FG boys public high school Bannu Cantt " 
    }, 
    "type": "High School" 
}, 
{ 
    "school": { 
    "id": "109989", 
    "name": "University of Engineering & Technology" 
    }, 
    "type": "College" 
} 
], 
"id": "xxxxxxx" 
} 

现在我需要学校的名字从这个XML,

+0

xml or json?你正在混合这两个,让你的问题有点混乱,从你发布它看起来像json而不是xml – nizammoidu

回答

1

试试这个..

您响应是JSON格式而不是XML。

JSONObject json = new JSONObject(response); 
JSONArray education = json.getJSONArray("education"); 
for(int i = 0; i < education.length(); i++){ 
    JSONObject con_json = education.getJSONObject(i); 
    String school_type = con_json.getString("type"); 
    JSONObject school_json = con_json.getJSONObject("school"); 
    String school_name = school_json.getString("name"); 
} 
0

它不是XML。它完全在Json标准格式。 首先从您的数据建立一个JSONObject:

JSONObject jsonObj = new JSONObject(result); //result = your Data String in fetched from server 

那么你驾驶室检索要使用什么关键。例如:

jsonObj.getString("id"); // it returns "xxxxxxx". as is in your data