2016-10-01 5 views
0

にジャクソンコンバータでの作業私は、JSONレスポンスがこのアンドロイド

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

ようになりましたが、私が最初にJSON response.Theの第二のPOJOを持って

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

このような方法でそれをしたいです1つは同じ会社名のアイテムを保持しています。どのように2番目のものに変換できますか?

答えて

0

私はひどくジャクソンコンバータserialization.andでこのプロジェクトを行うために探していますSorry.Nowも、このコードはあなたの応答をtoo.Thanksを動作しません。この

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

を試すことができます:) –