Aller au contenu
View in the app

A better way to browse. Learn more.

Forum de Frandroid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

traitement de données JSON

Featured Replies

Posté(e)

Bonjour à tous,

Je coince sur un truc : j'ai des données au format JSON de ce type :


{ "data" : {
  "id" : 1,
  "nom" : "Norris",
  "prenom" : "Chuck"
},
 "result" : "Informations sur l'utilisateur",
 "status" : 200
}

Mais je ne connais pas forcément le contenu de "data" (ni les clés, ni les valeurs).

Je voudrais parcourir le JSONObject "data" et afficher la clé et la valeur.

Un truc de ce genre (code totalement fictif ;) ) :

jObject = new JSONObject(string_des_donnee_json);

JSONObject dataItem = jObject.getJSONObject("data");

for (int i = 0; i < dataItem.lenthg(); i++) {

Log.i(dataItem.getKey());

Log.i(dataItem.getValue());

}

Si vous avez des idées, je suis preneur !

Merci d'avance !

Posté(e)
  • Auteur

Bon, en fait j'ai trouvé :)

		jObject = new JSONObject(string_des_donnee_json);
		// les infos
		if(!jObject.isNull("data")) {
			JSONObject dataItem = jObject.getJSONObject("data");
			if(dataItem.length()>0) {
		   	 //Map<String,String> map = new HashMap<String,String>();
   			 Iterator iter = dataItem.keys();
   			 while(iter.hasNext()){
   				 String key = (String)iter.next();
   				 String value = (String)dataItem.getString(key).toString();
   				 //map.put(key,dataItem.getString(key));	   				
   			 }
			}
		}

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Account

Navigation

Rechercher

Rechercher

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.