JSON (JavaScript Object Notation) is a popular data format used for representing structured data. It is often used when data is sent from a server to a web page. One of the common issues encountered when working with JSON is how to access array values inside an object in a JSON response. This can be a tricky problem to solve, but there are a few different approaches that can be used to access array values inside an object in a JSON response. In this article, we will discuss some of the different methods for solving this problem.
This question already has an answer here:
Accessing an array inside an object in a JSON response 3 answers
You can access the array values inside an object in a JSON response by using the dot notation. For example, if the JSON response looks like this:
{
“name”: “John”,
“age”: 30,
“hobbies”: [“swimming”, “hiking”, “reading”]
}
You can access the array values by using the dot notation like this:
var hobbies = response.hobbies; // [“swimming”, “hiking”, “reading”]
Try this…
JSONObject json = new JSONObject(response);
JSONObject json2 = json.getJsonObject("data");
JSONArray contacts = json2.getJSONArray("todayCallBacks");
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
}