2017-07-08 60 views
0

的JSONObject的樣子在android中的JSONObject解析?

{"result": 
    { 
     "id":"1", 
     "name":"ankur", 
     "email":"[email protected]", 
     "address":"bblock", 
     "designation":"devloper", 
     "department":"development", 
     "balanceleave":"5" 
    } 
} 

和我解析的代碼看起來像

Intent intent = new Intent(Login.this, Profile.class); 
intent.putExtra("id", response.getString("id")); 
intent.putExtra("name", response.getString("name")); 
intent.putExtra("email", response.getString("email")); 
intent.putExtra("address", response.getString("address")); 
intent.putExtra("designation", response.getString("designation")); 
intent.putExtra("department", response.getString("department")); 
intent.putExtra("balanceleave", response.getString("balanceleave")); 

startActivity(intent); 

你能幫助我,其實我解析的JSON,並將其發送到配置文件活動顯示,如果你可以拿出一些東西,我可以發送JSONObject的配置文件,這將是偉大的!

+0

確切的問題是什麼?你需要在某個地方解析它嗎?建議:使用Gson –

回答

1

嘗試這樣的:

JSONObject response=new JSONObject("your response string"); 
JSONObject result=response.getJSONObject("result"); 
String id=result.getString("id"); 
String name=result.getString("name")); 
String email=result.getString("email")); 
String address=result..getString("address")); 
String designation=result.getString("designation")); 
String department=result.getString("department")); 
String balanceleave=result.getString("balanceleave")); 
+0

感謝兄弟你回答我的第二個即將到來的問題。 –

+0

歡迎@YashKumarAtri – Akash

0

是的,你必須將JsonObject轉換爲String然後通過Bundle發送到配置文件屏幕。像下面

Intent intent = new Intent(Login.this, Profile.class); 
intent.putExtra("JSON_OBJECT", response.toString()); 


           startActivity(intent); 

要獲得

Intent i = getIntent(); 
String json = i.getStringExtra("JSON_OBJECT"); 
try{ 
JsonObject json = new JsonObject(json); 
}catch(Exception e){ 
} 
0

你可以寫下面一行

JSONString url = objectname.getJsonString("url"); 

再放入意圖

+0

問題中沒有網址 –