lundi 11 janvier 2016

BEGINNER: Convert JSON string to hash

I have a Ruby on Rails JSON question.

I have what I think is a strange error. I have the following JSON string

test = "[{'domain': 'abc.com'}, {'domain': 'def.com'}, {'domain': 'ghi.com'}]"

Now, I want to convert this string to a hash using:

hash = JSON.parse test

The problem is that it errors with:

JSON::ParserError: 419: unexpected token at '{'domain': 'abc.com'}, {'domain': 'def.com'}, {'domain': 'ghi.com'}]'

Anyone have a clue?

Aucun commentaire:

Enregistrer un commentaire