Parsing Double[] Within Json Array In Android
Im new to android all i have used previously is that i get JSON Array from server and parsed JSON objects like following,, JSONObject objResponse = new JSONObject(retResult); Strin
Solution 1:
The property iapStandardHeight
looks to be a jagged array. This looks to be the most complicated bit of the json you are receiving. Below is code for creating a jagged double array from the json you posted. If you need more help, just add a comment.
JSONObject jsonResponse = newJSONObject(response);
JSONArray outerArray = jsonResponse.getJSONArray("iapStandardHeight");
double[][] result = new double[outerArray.length()][];
for(int i = 0; i < outerArray.length(); i++){
JSONArray innerArray = outerArray.getJSONArray(i);
double[] innerResult = new double[innerArray.length()];
for(int j = 0; j < innerArray.length(); j++){
innerResult[j] = innerArray.getDouble(j);
}
result[i] = innerResult;
}
Solution 2:
try this
try {
JSONObject objResponse = newJSONObject(retResult);
JSONArray arr = objResponse.getJSONArray("iapStandardHeight");
for(int i=0; i<arr.length(); i++){
JSONArray arr2 = arr.getJSONArray(i);
for(int j=0; j<arr2.length(); j++){
double value = arr2.getDouble(j);
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Post a Comment for "Parsing Double[] Within Json Array In Android"