How can I parse in Android a Json array of strings and save it in a java string array ( like: xy[ ] ) ?
My Json to be parsed :
 [
  {
    "streets": [ "street1", "street2", "street3",... ],
  }
 ]
Later in my code I want to populated with that array a spinner item in my layout. Everything i tried enden with only one street item listed in the spinner.
To parse
try {
   JSONArray jr = new JSONArray("Your json string");
   JSONObject jb = (JSONObject)jr.getJSONObject(0);
   JSONArray st = jb.getJSONArray("streets");
   for(int i=0;i<st.length();i++)
       {
      String street = st.getString(i);
      Log.i("..........",""+street);
      // loop and add it to array or arraylist
        }
}catch(Exception e)
{
        e.printStackTrace();
}
Once you parse and add it to array. Use the same to populate your spinner.
[ represents json array node
{ represents json object node
Try this..
 JSONArray arr = new JSONArray(json string);
    for(int i = 0; i < arr.length(); i++){
            JSONObject c = arr.getJSONObject(i);        
            JSONArray ar_in = c.getJSONArray("streets");
        for(int j = 0; j < ar_in.length(); j++){    
            Log.v("result--", ar_in.getString(j));
        }
   }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With