Reputation: 493
[{"name":"Mark","Surname":"Gaux"}]
[{"Job":"2","Type":"Office"}]
I have this JSON echoed by a PHP file on the server and then received by my Android application.
Since I didn't manage to merge the two into one array [ ], you notice that I have two arrays [] [].
When I had one array I parsed it in my Android application using this loop:
try{
JSONArray jArray = new JSONArray(response);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
jname = json_data.getString("name");
jsurname = json_data.getString("Surname");
...
}
Just a simple example.
I'm a bit confused concerning JSONArray and JSONObject. JSONArray is anything between [] and JSONObject is anything between {} ?
Well now that I have two arrays, how do I loop from one into the other?
Or am I better off merging them into one array from the PHP and using the technique I used up to now?
Upvotes: 0
Views: 3210
Reputation: 8787
If you're trying to send both arrays in one response you could do that:
[
[{"name":"Mark","Surname":"Gaux"}],
[{"Job":"2","Type":"Office"}]
]
Whole JSON string is a JSONArray
:
getJSONArray(0)
contains JSONObject
s with name
and Surname
getJSONArray(1)
contains JSONObject
s with Job
and Type
Upvotes: 1