I would like to convert the following string into an array/nested array and iterate through it, so that i could use values from it.
str = "[[{"one": "1"}],[{"two": "2"}],[{"three": "3"}]]"
// I want to use value inside the {} brace
I would like to convert the following string into an array/nested array and iterate through it, so that i could use values from it.
str = "[[{"one": "1"}],[{"two": "2"}],[{"three": "3"}]]"
// I want to use value inside the {} brace
That is JSON(*), and can be parsed as JSON.
require 'json'
data = JSON.parse(str)
And then you can use the usual Array#each or Hash#each iterators.
*) Or at least it would be JSON, if it wasn't a syntax error. You can't have an unescaped double quote inside double quotes.
ele[0]["one"] to get to the "1", or onion together two each loops (one for the outer Array, one for the inner Array).