-1

I am trying to parse JSON data in my Rails 4 application with JSON.parse. I keep getting this error:

757: unexpected token at '<?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>BB0CDD4F68DBE9C0</RequestId><HostId>SwLqpcx7wpspbYzXONm1XGRG46dGHxnDroplppsxqtU4v/iVwEGOvpRWpBNR+LMPduTldva/5Nk=</HostId></Error>'

enter image description here

4
  • 2
    Looks like response isn't in the json format. Did you look at error message? Commented Sep 2, 2017 at 10:25
  • Possible duplicate of Ruby on Rails JSON.parse unexpected token error Commented Sep 2, 2017 at 11:11
  • Questions that ask "please help me" tend to be looking for highly localised guidance, or in some cases, ongoing or private assistance, which is not suited to our Q&A format. It is also rather vague, and is better replaced with a more specific question. Please read Why is “Can someone help me?” not an actual question? Commented Sep 2, 2017 at 11:12
  • Further pro tip: adding this to your questions gives the appearance of begging and pleading, and you may get better responses if you keep your posts short and to the point. Commented Sep 2, 2017 at 11:14

1 Answer 1

2

Looks like error response is not returned as JSON. You could do something like:

def reviews
  JSON.parse(reviews_json)['Reviews']
rescue JSON::ParserError
  []
end
Sign up to request clarification or add additional context in comments.

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.