2016-07-26 12 views
-1

JSONレスポンスがあり、JSON配列内にJSON配列があります。それを解析する方法を教えてください。複数のJSON配列の解析のための最良の例だと教えてください。開発者が私にこのような応答を与えるように、私はすべてのフィールドダイナミックを持っています。前もって感謝します。JSONレスポンスを解析する方法

{ 
"products": [ 
    { 
     "id": "14", 
     "cat_id": [ 
     "1" 
     ], 
     "category_name": [ 
     "Meetha Paan Sall Supari" 
     ], 
     "name": "Chocco Paan", 
     "product_image": "http://freedemo.info/paanvaala/php/media/product_image/t0xdfosjr_1_173_201.png", 
     "price_unit": "in_pcs", 
     "price_id": [ 
     "14" 
     ], 
     "weight": [ 
     "1 PCS" 
     ], 
     "price": [ 
     150 
     ], 
     "mrp": [ 
     "150.00" 
     ], 
     "description": null 
    }, 
    { 
     "id": "13", 
     "cat_id": [ 
     "1" 
     ], 
     "category_name": [ 
     "Meetha Paan Sall Supari" 
     ], 
     "name": "Chochobar Pan", 
     "product_image": "http://freedemo.info/paanvaala/php/media/product_image/hul6e69n6_1_173_201.png", 
     "price_unit": "in_pcs", 
     "price_id": [ 
     "13" 
     ], 
     "weight": [ 
     "1 PCS" 
     ], 
     "price": [ 
     85 
     ], 
     "mrp": [ 
     "85.00" 
     ], 
     "description": null 
    }, 
    ], 
} 
+0

この質問には、追加の書式設定と説明が役立ちます。あなたのユースケースは何ですか?そこから抽出したいデータはありますか?あなたが投稿する前に – adeora

+1

Googleの検索では、例のトーンがある –

+0

多くの例が存在していた最初にそれを試して、あなたはより良い知識を得るでしょう。 –

答えて

0

JSONを構文解析する方法とその内容はhereに従ってください。

enter image description here

+0

私は、複数のjson配列を解析する例が必要です –

0

解析JSON:例外のトライキャッチで

JSONObject jsonObj = new JSONObject(jsonStr);// your string. 
JSONArray jsonArray = jsonObj.getJSONArray("products"); 


for(int i=0; i < jsonArray.length(); i++){ 
     JSONObject prod = jsonArray.getJSONObject(i); 
     String id = prod.getString("id"); 

     // and so on ...you can parse the entire json using either array or object 

} 

サラウンド....

0

あなたはJSONが有効であるかない場合は、yをVERIFする必要がありまず。 Json Validator

あなたは、この有効なそして `

try { JSONObject jsonRootObject = new JSONObject(strJson); 
     //Get the instance of JSONArray that contains JSONObjects 
     JSONArray jsonArray = jsonRootObject.optJSONArray("products"); 
     //Iterate the jsonArray and print the info of JSONObjects 
     for(int i=0; i < jsonArray.length(); i++){ 
      JSONObject jsonObject = jsonArray.getJSONObject(i); 
      int id = Integer.parseInt(jsonObject.optString("id").toString()); 
      String name = jsonObject.optString("name").toString(); 
      float product_image = Float.parseFloat(jsonObject.optString("product_image").toString()); 
     JSONArray cat_idArray = jsonRootObject.optJSONArray("cat_id");  
     for(int i=0; i < cat_idArray.length(); i++){ 
     //Here you can get other values 
      } 
      data += "Node"+i+" : \n id= "+ id +" \n Name= "+ name +" \n Salary= "+ salary +" \n "; 
     } 
     output.setText(data); 
     } catch (JSONException e) {e.printStackTrace();} 

` を発見した場合も、あなたが学ぶことができるウェブの例がたくさんあります。 like this one

関連する問題