I have a JSON with the below structure:
[
{
"timestamp": "2019-07-12 00:29:37",
"OutletTemperatureCV": "31.5",
"ChocolateMixingTemperatureCV": "30.399999",
"WaterCoolingTemperatureCV": "13.899",
"WaterMixingTemperatureCV": "31.5"
}
]
The Json file is named as temperer. I am trying to parse this json array to get values values.
JSONArray array1=new JSONArray(temperer);
for (int n = 0; n < array1.length(); n++) {
JSONObject jsonObject = array1.getJSONObject(n);
String time= jsonObject.getString("timestamp");
String outletTemp= jsonObject.getString("OutletTemperatureCV");
String outletTemp= jsonObject.getString("ChocolateMixingTemperatureCV");
String outletTemp= jsonObject.getString("WaterCoolingTemperatureCV");
String outletTemp= jsonObject.getString("WaterMixingTemperatureCV");
}
But when I try this code, I get the below error..
org.json.JSONException: JSONArray initial value should be a string or collection or array.
I saw another post in SO with a similar prob, but this example uses a named JSON array. (Parsing JSON Array within JSON Object)
How can I get over this error for an unnamed JSON array? Any solutions will be hugely helpful :(
temperer? It should be of String type containing the json string.