I have been working with a few JSON objects and have been keeping the outer JSON an array, but is it possible to keep the outer a JSON object and have it contain other JSON objects or arrays?
This is what I have and it is in proper form and works well:
{
"outer":[{
"profile":{
"image":"",
"name":"",
"password":"",
"favorites":[
]
},
"friends":[
{
"name":"",
"image":"",
"number":"",
"type":"",
"birthday":"",
"state":""
}
]
}]
}
However, is it possible to have this:
{
"outer":{
"profile":{
"image":"",
"name":"",
"password":"",
"favorites":[
]
},
"friends":[
{
"name":"",
"image":"",
"number":"",
"type":"",
"birthday":"",
"state":""
}
]
}
}
This is also in proper form, but I am having trouble adding multiple JSON objects and JSON arrays to a single JSON object in Android. Every time I have the outer JSON object, it overwrites whichever object is already in there when I add another one.
This is what I've got so far. obj1 is the profile JSON object and obj2 is the friends JSON object:
JSONObject profile = new JSONObject();
profile.put("profile", obj1);
JSONObject friends = new JSONObject();
friends.put("friends", obj2);
JSONObject outer = new JSONObject():
outer.put("outer", profile);
outer.put("outer", friends);