我有此JSON獲得價值Android的 - 從JSON對象
{
"results": [
{
"user": {
"gender": "male",
"name": {
"title": "mr",
"first": "herbert",
"last": "davidson"
},
"location": {
"street": "9763 fincher rd",
"city": "melbourne",
"state": "new south wales",
"zip": 26278
},
"email": "[email protected]",
"username": "lazyelephant581",
"password": "abgrtyu",
"salt": "O8ZbSsUL",
"md5": "7575bd959be09bc6d510a6a91750ce40",
"sha1": "0db99de8402e1defbd7935dbd602d99329698d4d",
"sha256": "c283d262115f90b729bb555db3dbecc8d27eebed513d7f01da799dec9e9d3269",
"registered": 1275070071,
"dob": 122409280,
"phone": "05-5742-3228",
"cell": "0481-652-548",
"TFN": "973720989",
"picture": {
"large": "https://randomuser.me/api/portraits/men/24.jpg",
"medium": "https://randomuser.me/api/portraits/med/men/24.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/men/24.jpg"
}
}
}
],
"nationality": "AU",
"seed": "0a69317ece7072e000",
"version": "0.7"
}
和IM這樣做:(結果是JSON從服務返回)
try{
JSONObject jsonResponse = new JSONObject(result);
JSONObject jo = jsonResponse.getJSONObject("user");
String nome = jo.getString("username");
}catch(Exception e) {
e.printStackTrace();
}
,但給我這個錯誤
org.json.JSONException:沒有用戶名值
什麼即時做錯了?我試圖做一個JSONArray,試圖從另一個jsonobject獲取jsonobject,但發出一個錯誤,無法將jsonobject轉換爲jsonarray。
問候!
Rafael
@RafaelSpessotto祝你! – KeLiuyue