mercredi 1 avril 2015

I have json that looks like the following



{
"tiles":[
{
"header":"Manual",
"subheader":"Login",
"summary1_label":"",
"summary2_label":"",
"summary3_label":"",
"summary4_label":"",
"summary1_value":"",
"summary2_value":"",
"summary3_value":"",
"summary4_value":"",
"iconUrl":"http://ift.tt/1C39tpD"
},
{
"header":"NewUser",
"subheader":"Login",
"summary1_label":"",
"summary2_label":"",
"summary3_label":"",
"summary4_label":"",
"summary1_value":"",
"summary2_value":"",
"summary3_value":"",
"summary4_value":"",
"iconUrl":"http://ift.tt/1OVVAUg"
},
{
"header":"Facebook",
"subheader":"Login",
"summary1_label":"",
"summary2_label":"",
"summary3_label":"",
"summary4_label":"",
"summary1_value":"",
"summary2_value":"",
"summary3_value":"",
"summary4_value":"",
"iconUrl":"http://ift.tt/1C39tpF"
}
]
}


I cast this as a JsonObject and send it to a reformating method. in that method i do the following



public ArrayList<String[]> formatHttpResponse_SummaryTile(JSONObject json) throws JSONException {
ArrayList<String[]> arrayList_summary = new ArrayList<String[]>();
JSONArray tilesArray = json.getJSONArray("tiles");
//JSONObject allTilesData = json.getJSONObject("tiles");
for (int i=0; i<tilesArray.length(); i++)
{
//JSONObject thisJsonObject = tilesArray.getJSONObject(i);
JSONArray thisJsonArray = tilesArray.getJSONArray(i);
String[] thisStringArray = new String[thisJsonArray.length()];
for (int j=0; j<thisJsonArray.length(); j++)
{
thisStringArray[j]=thisJsonArray.getString(j);
}
arrayList_summary.add(thisStringArray);
}
return arrayList_summary;
}


As you can see i create an array list then cycle through my jsonObjects 3 children. Now the problem is that i want to convert the children to String[][ but my code bugs out at JSONArray thisJsonArray = tilesArray.getJSONArray(i); as it isnt a jsonArray.


Any idea how i can get the children above into 3 string arrays all added to a arrayList Is there a more efficent, straight cast i can do?


Aucun commentaire:

Enregistrer un commentaire