Json object android retrofit
Résolu
DalyMHY
Messages postés
7
Statut
Membre
-
DalyMHY Messages postés 7 Statut Membre -
DalyMHY Messages postés 7 Statut Membre -
Bonjour,
J'ai cette fonction qui retourne une réponse Json détaillée, je juste avoir l'id comment faire s'il te plait ?
J'ai cette fonction qui retourne une réponse Json détaillée, je juste avoir l'id comment faire s'il te plait ?
public void onResponse(Call<String> call, Response<String> response) {
if (response.isSuccessful()) {
if (response.body() != null) {
Log.i("Responsestring", response.body().toString());
Log.i("onSuccess", response.body().toString());
String jsonresponse = response.body().toString();
try {
JSONObject jsonObject = new JSONObject(jsonresponse);
if (jsonObject.getString("status").equals("success")) {
Toast.makeText(getActivity(), "Login Successfully!", Toast.LENGTH_SHORT).show();
Intent intent;
intent = new Intent(getActivity(), ActivityListEvents.class);
startActivity(intent);
Log.i("DATA", jsonObject.getString("data"));
}
I/Responsestring: {"status":"success","data":{"id":2,"name":"user","prenom":"user"}}
I/onSuccess: {"status":"success","data{"id":2,"name":"user","prenom":"user"}}
I/DATA: {"id":2,"name":"user","prenom":"use"}}
A voir également:
- Json object android retrofit
- Android recovery - Guide
- Begone android - Accueil - Protection
- Presse papier android - Guide
- À quoi sert google drive sur android - Guide
- Emulateur pokemon android - Guide
2 réponses
Tu n'as pas dû chercher beaucoup ;)
Aller, c'est bien parce que c'est rapide à faire...A priori, il te suffit de faire ceci :
Aller, c'est bien parce que c'est rapide à faire...A priori, il te suffit de faire ceci :
if (response.isSuccessful() && response.body() != null) {
String jsonresponse = response.body().toString();
try {
JSONObject jsonObject = new JSONObject(jsonresponse);
if (jsonObject.getString("status").equals("success")) {
JSONObject jsonData = jsonObject.getString("data"));
int id = jsonData.getInt("id");
}
...
Hello,
Tu peux parcourir ton JSONObject avec les méthodes
Plus d'infos ici
Tu peux parcourir ton JSONObject avec les méthodes
get(),
getJSONObject(),
getString().
Plus d'infos ici
J'ai réussi à trouver la solution