0

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 ?

5
  • Invalid JSON Commented Jan 11, 2017 at 8:00
  • 2
    your json is invalid , check response at jsonlint.com Commented Jan 11, 2017 at 8:03
  • 1
    @IntelliJAmiya , It is invalid because it has no square brackets ' [ ' ? Commented Jan 11, 2017 at 8:05
  • @AnitaAlvekodi yes Commented Jan 11, 2017 at 8:06
  • also there is no problem in parsing this in iOS , isn't there a way to parse it in android ? Commented Jan 11, 2017 at 8:08

2 Answers 2

1

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 :-)

Sign up to request clarification or add additional context in comments.

Comments

0

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.