2014-06-12 36 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