2016-10-01 1 views
0

J'ai une réponse JSON ressemble à ceTravailler avec Jackson Converter dans Android

"pen": [ 
       { 
        "company": "Lexi", 
        "ink": "red", 
        "instock": true 
       }, 
       { 
        "company": "Lexi", 
        "ink": "blue", 
        "instock": true 
       } 
      ] 

Mais je veux dans cette façon

"pen": [ 
       { 
      "company": "Lexi", 
        "items":[ 
       { 
        "ink": "red", 
        "instock": true 
       } 
       { 
        "ink": "blue", 
        "instock": true 
       } 
      ] 
     } 
    ] 

Je le POJO de la première JSON réponse.Dispositif seconde on tient les articles avec le même nom de société. Comment puis-je le convertir en le deuxième ?.

Répondre

0

vous pouvez essayer cette

try { 

      JSONObject jsonObject = new JSONObject(result); //result = your stream result 

      String company = jsonObject.getString("pen"); //this what you got now 

      JSONArray array = new JSONArray(company); 

      for (int i = 0; i < array.length(); i++) { 

       JSONObject jsonPart = arr.getJSONObject(i); 

       Log.i("Company", jsonPart.getString("company")); 


       } 
catch(Exception e) 
{ 

} 
+0

Sorry.Now Je cherche terriblement à faire ce projet avec convertisseur jackson serialization.and également ce code ne fonctionne pas too.Thanks pour votre réponse :) –