2017-07-08 1 views
0

Le JSONObject ressembleJSONObject analyse dans android?

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

et mon code d'analyse syntaxique ressemble

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); 

Pouvez-vous me aider, en fait je suis l'analyse du JSON et l'envoyer à l'activité de profil pour afficher et si vous peut comeup avec quelque chose que je peux envoyer le JSONObject pour profiler ce serait génial !!

+0

Quel est le problème exact? Vous aurez besoin de l'analyser quelque part, n'est-ce pas? Recommandation: Utilisez Gson –

Répondre

1

Essayez comme ceci:

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

Merci mon frère de répondre à ma deuxième question à venir. –

+0

Bienvenue @YashKumarAtri – Akash

0

oui vous devez convertir JsonObject en String et ensuite envoyer via Bundle à l'écran de profil. Comme ci-dessous

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


           startActivity(intent); 

Pour obtenir ce

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

Vous pouvez écrire ci-dessous la ligne

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

puis mis dans l'intention

+0

Il n'y a pas d'URL dans la question –