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

1
  • 1
    that's XML! { "json": { "looks": "like this" } } Commented May 28, 2013 at 21:32

1 Answer 1

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?

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

3 Comments

The API will only return an xml response, how can I convert that into json object
you will need to parse it using a ruby XML parser into a ruby type, then if you want to convert it from there you have to json encode it
@Ramya I have edited my question to include an answer to your question.

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.