2012-03-19 14 views
0

私は、JSONのこのモデルがあります:解析JSONは

{ 
    "conditions":[ 
     "Offre non cumulable avec les promotions internes de playland", 
     "Le centre ferme le lundi", 
     "R\u00e9servation \u00e0 l'avance au 0661977474", 
     "Les mineurs doivent remplir l'autorisation parentale sur le site www.playland.ma", 
     "Valable sur pr\u00e9sentation d'une carte d'identit\u00e9 avec le bon", 
     "Le forfait inclut les \u00e9quipements, les protections, le remplissage gaz et l'assurance", 
     "Offre valable 1 mois du 1 Mars au 31 mars 2012" 
    ] 
} 

をし、私はそれを解析し、1つの文字列に入れる必要があるが、私は行うことができないコード理由私が使用していることを、この配列では最初の値のみを解析し、これはコードです:

JSONArray c = deals.getJSONArray(condition); 
      for(int i = 0; i < c.length(); i++){ 
       String Precision = c.getString(i);} 

答えて

0

あなたは単にJavaでオブジェクトにopearteとJSONと副詩にオブジェクトを変換することができGsonを使用することができます。 Gsonため

リンクがある -

http://code.google.com/p/google-gson/

0

これを試してみてください、それはあなたを助けるかもしれません。

JSONObject jObject = new JSONObject(jsonResponseString); 

JSONObject arrObject = jObject.getJSONArray("Tagname"); 

for (int i = 0, len = arrObject.length(); i < len; i++) 
{ 
    JSONObject json = arrObject.getJSONObject(i); 
    System.out.println(json.getString("value1").toString()); 
    System.out.println(json.getString("value2").toString()); 
} 
0

このコードを試してください。私の最後にはうまくいきます。

public class SampleActivity extends Activity 
{ 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     String json = "[\"Offrenoncumulableaveclespromotionsinternesdeplayland\",\"Lecentrefermelelundi\",\"Réservationàl'avanceau0661977474\",\"Lesmineursdoiventremplirl'autorisationparentalesurlesitewww.playland.ma\",\"Valablesurprésentationd'unecarted'identitéaveclebon\",\"Leforfaitinclutleséquipements,lesprotections,leremplissagegazetl'assurance\",\"Offrevalable1moisdu1Marsau31mars2012\"]"; 
     try 
     { 
      JSONArray array = new JSONArray(json); 

      for (int i = 0, len = array.length(); i < len; i++) 
      { 
       Log.i("info", array.getString(i)); 
      } 

     } catch (JSONException e) 
     { 
      e.printStackTrace(); 
     } 

    } 

} 

このヘルプが必要です。

+0

解決策はありませんが、何も変更されていません –

0

これを試してください:-Vipul shahが正しいです。

package com.ap.test; 

import org.json.JSONArray; 
import org.json.JSONException; 

import android.app.Activity; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.TextView; 

public class StestActivity extends Activity 
{ 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    StringBuffer sb = new StringBuffer(); 

    String json = "[\"Offrenoncumulableaveclespromotionsinternesdeplayland\",\"Lecentrefermelelundi\",\"Réservationàl'avanceau0661977474\",\"Lesmineursdoiventremplirl'autorisationparentalesurlesitewww.playland.ma\",\"Valablesurprésentationd'unecarted'identitéaveclebon\",\"Leforfaitinclutleséquipements,lesprotections,leremplissagegazetl'assurance\",\"Offrevalable1moisdu1Marsau31mars2012\"]"; 
    try 
    { 
     JSONArray array = new JSONArray(json); 

     for (int i = 0, len = array.length(); i < len; i++) 
     { 
      Log.i("info", array.getString(i)); 

      sb.append(array.getString(i)); 

     } 

     TextView sname = (TextView) findViewById(R.id.id_activity_lat); 
     sname.setText(sb.toString()); 

    } catch (JSONException e) 
    { 
     e.printStackTrace(); 
    } 

    } 

}