1
<?xml version="1.0" encoding="UTF-8"?><ns1:User xmlns:ns1="http://www.xxxxx.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:axis2ns11869="http://www.xxxxxx.com"><ns2:CC xmlns:ns2="http://www.xxxxx.com">name</ns2:CC></ns1:User>

This is the response, I am got back from invoking an api. I then tried to Parse it in Json, I get an error 757 unexpected token

responseHash = JSON.parse(response.body)

Any idea on whats wrong here?

Thanks Ramya

Ramya
  • 107
  • 1
  • 1
  • 12

1 Answers1

2

The data you are getting back from the API is XML instead of JSON. So there is no way for you to parse that as JSON because the data formats are totally different.

You need to go back and check to see if the API is able to respond with JSON or if they make you request JSON in the Content-Type header. If they are able to respond with JSON, then make your Content-Type header "application/json"

Edit:

I found a question that answers your comment on how to convert xml into json.

Ruby XML to JSON Converter?

Community
  • 1
  • 1
TheBinaryhood
  • 231
  • 2
  • 9