2

I have a JSON Object returned from server.

{
  "SOAP-ENV:Envelope": {
    "SOAP-ENV:Body": {
      "ADDWEBSOperationResponse": {
        "Num1": 10,
        "Result": 20,
        "Num2": 10,
        "xmlns": "http://www.**.**.Response.com"
      }
    },
    "xmlns:SOAP-ENV": "http://schemas.xmlsoap.org/soap/envelope/",
    "xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
    "xmlns:add": "http://www.**.**.Request.com"
  }
}

I wanted to print Result in my page. I was trying with data.Resultbut its not displaying the value.

2
  • 1
    data["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["ADDWEBSOperationResponse"].Result Commented Aug 22, 2016 at 6:47
  • And in case your data is formatted as string, do this first JSON.parse(data) Commented Aug 22, 2016 at 6:48

4 Answers 4

4

Use bracket notation as it is particularly useful for non-identifier-safe characters and also for accessing keys that you may not know ahead of time

data["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["ADDWEBSOperationResponse"]["Result"]
Sign up to request clarification or add additional context in comments.

Comments

3

Try it with

data['SOAP-ENV:Envelope']['SOAP-ENV:Body']['ADDWEBSOperationResponse'].Result

1 Comment

I am getting a JSON string from the server.. I didn't convert it to object. But still this worked for me.. But i wonder how can i convert it to JSON object. I tried JSON.parse(data). But it didn't work for me.
1

I should be

data["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["ADDWEBSOperationResponse"].Result

You need to follow the hierarchy.

JSFIDDLE

Comments

1
data["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["ADDWEBSOperationResponse"].Result

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.