B
B
Bogdan2017-07-24 12:26:57
Ruby on Rails
Bogdan, 2017-07-24 12:26:57

How to convert a string into an array?

Hello. How can I convert a string into an array? The example below does not work. Thank you.

require 'json'

str = '[ { :aa => "1" }, { :aa => "2" } ]'
value = JSON.parse( str )

puts str

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur, 2017-07-24
@TheSunwave

Invalid JSON at the input, JSON::ParserError at the output, everything seems to be correct.
Try
str = '[ { "aa": "1" }, { "aa": "2" } ]'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question