I get a JSON in following format
{
"goods" : {
"t1" : {
"name" : "name1"
},
"t2" : {
"name" : "name2"
}
}
}
In PHP and Angular that works fine
In android studio I get the following error
W/System.err: org.json.JSONException: Unterminated array at character 23 of {
W/System.err: "goods" : [
W/System.err: "t1" : {
W/System.err: "name" : "name1"
W/System.err: },
W/System.err: "t2" : {
W/System.err: "name" : "name2"
W/System.err: }
W/System.err: ]
W/System.err: }
It works fine When in the following structure
{
"goods" : [
{
"name" : "name1"
},
{
"name" : "name2"
}
]
}
But the problem is I get a JSON from the Server in : many objects in object, not : many objects in Array. Is there any way to make this work, i can't change the structure from the server, because on that Json works many other web sites. Please help !!!!!!!!!!!!!
Here is code how i use it
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
JSONArray contacts = jsonObj.getJSONArray("goods");
// looping through All Contacts
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
String name = c.getString("name");
Log.e("JSON : ", name);
}
} catch (JSONException e) {
e.printStackTrace();
}