I am trying to fetch details from the JSON with URL - https://thingspeak.com/channels/133098/field/1.json
But it always return null value. Please help to find the proper code to fetch the value from the respective cloud into my Android application.
JSON file
{
"channel": {
"id": 133098,
"name": "Health Monitoring System",
"latitude": "0.0",
"longitude": "0.0",
"field1": "Temp",
"field2": "Hum",
"field3": "Pressure",
"field4": "Pulse",
"field5": "Acc",
"field6": "BP Sys",
"field7": "BP Dia",
"created_at": "2016-07-11T07:06:18Z",
"updated_at": "2016-07-22T07:56:52Z",
"last_entry_id": 134
},
"feeds": [{
"created_at": "2016-07-21T12:17:17Z",
"entry_id": 35,
"field1": "93.59"
}, {
"created_at": "2016-07-21T12:18:08Z",
"entry_id": 36,
"field1": "93.59"
}, {
"created_at": "2016-07-21T12:18:59Z",
"entry_id": 37,
"field1": "93.59"
}, {
"created_at": "2016-07-22T04:49:44Z",
"entry_id": 38,
"field1": "0.00"
}, {
"created_at": "2016-07-22T04:50:41Z",
"entry_id": 39,
"field1": "95.16"
}, {
"created_at": "2016-07-22T04:51:25Z",
"entry_id": 40,
"field1": "95.16"
}, {
"created_at": "2016-07-22T04:52:17Z",
"entry_id": 41,
"field1": "95.16"
}]
}
My Android Code
private ArrayList<Number> temp;
JSONObject resultJsonObject = new JSONObject(URL);
JSONArray jsonArray = resultJsonObject.getJSONArray("feeds");
// temp = new Number[response.length()];
try {
for (int i = 0; i < response.length(); i++) {
final JSONObject json = jsonArray.getJSONObject(i);
temp.add(Float.parseFloat(json.getString(TAG_TEMP)));
Log.d("RESPONSE", json.getString("field1"));
}
//Toast.makeText(MainActivity.this, s.toString(), Toast.LENGTH_SHORT).show();
//Log.d("RESPONSE", s.toString());
} catch (JSONException e) {
e.printStackTrace();
}