I am getting response from server in JSONArray format. I am not able to retrieve the contents of array also my JSONArray has no Square brackets.
I am passing the response in php as json_encode($array) in server side
response {
community = "worker"
communitystr = "<null>";
workspace = abs;
email = "<null>";
admin = false;
persona = "<null>";
userinfo = {
info = {
contact1 = {
firstname = "jon";
lastname = "Doe"
phone = "9885678905";
objectname = contact;
id = 9;
};
event1 = {
eventname = "party";
description = "";
order = 6;
id = 4;
objectname = events;
};
files = {
filename = "sample";
description = "";
order = 11;
id = 11;
objectname = files;
};
};
};
};
I checked many links and all have used JSONObject(). But same is not working for me.
How do I get each values in this JSON Response ?
2 Answers 2
You have to use
: instead of =
, instead of ;
...
Watch out following format:
{
"Herausgeber": "Xema",
"Nummer": "1234-5678-9012-3456",
"Deckung": 2e+6,
"Waehrung": "EURO",
"Inhaber":
{
"Name": "Mustermann",
"Vorname": "Max",
"maennlich": true,
"Hobbys": [ "Reiten", "Golfen", "Lesen" ],
"Alter": 42,
"Kinder": [],
"Partner": null
}
}
Your code seems like to be more JavaScript-Object like :-)
Comments
Your response is not valid JSON object.
You can validate the JSON via some online tool, like http://jsonlint.com/
Full specification can be found in RFC 7159 https://www.rfc-editor.org/rfc/rfc7159.
Basically you should look how to encode the values into JSON format in correct way. For that you can refer to PHP Array to JSON Array using json_encode();
Invalid JSON