-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

halfer
  • 19,824
  • 17
  • 99
  • 186
Amrinder Singh
  • 5,300
  • 12
  • 46
  • 88
  • 2
    Looks like response isn't in the json format. Did you look at error message? – Roman Kiselenko Sep 02 '17 at 10:25
  • Possible duplicate of [Ruby on Rails JSON.parse unexpected token error](https://stackoverflow.com/questions/5130822/ruby-on-rails-json-parse-unexpected-token-error) – halfer Sep 02 '17 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?](//meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) – halfer Sep 02 '17 at 11:12
  • Further pro tip: adding this [to your questions](https://stackoverflow.com/search?q=user%3A3164751+please+is%3Aquestion) gives the appearance of begging and pleading, and you may get better responses if you keep your posts short and to the point. – halfer Sep 02 '17 at 11:14

1 Answers1

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
Jan Klimo
  • 4,643
  • 2
  • 36
  • 42