Android 解析JSON數據

1.下面的代碼返回從服務器取來的JSon類型數據 json

    result = new String(EntityUtils.toString(response.getEntity(),
      "utf-8"));

 

2.JSON對象是{}內的數據,數據以數據對方式給出,如「name」:"william".一個JSon對象裏面可能包含其餘JSon對象。[]表示JSon對象數組,裏面包含多個JSon對象。 數組

下面是一條json數據(String類型): 服務器

{"profile":[{"name":"william","age":28},{"name":"jack","age":30}]"} spa

 

解析過程: 對象

JSONObject jsonobject=new JSONObject(string); utf-8

JSONArray jsonarray=jsonobject.getJSONArray("profile"); get

JSONObject tempJSon; string

for(int i=0;i<jsonarray.length;i++){ it

      tempJSon=jsonarray.getJSONObject(i); object

      //對取到的JSONObject對象進行處理

      ...

}

相關文章
相關標籤/搜索