Now, among the rest, I also want to access those "ruby", "json" and
"library" strings.
With the following code:
@structs = JSON.parse(@json_stream)
for i in 0...@structs.length @struct_obj = @structs.fetch(i) @struct_obj.each { |key, value|
if key == "t"
# get the value that 't' points to
end
}
end
I get them all appended to each other without any whitespace, ie
"rubyjsonlibrary".
Now, among the rest, I also want to access those "ruby", "json" and
"library" strings.
With the following code:
@structs = JSON.parse(@json_stream)
for i in 0...@structs.length @struct_obj = @structs.fetch(i) @struct_obj.each { |key, value|
if key == "t"
# get the value that 't' points to
end
}
end
I get them all appended to each other without any whitespace, ie
"rubyjsonlibrary".
How could I access them individually?
Marko
for i in 0...@structs.length @struct_obj = @structs.fetch(i) @struct_obj.each { |key, value|
if key == "t"
# get the value that 't' points to
#the value that t points to is stored in your 'value' variable
value.each do |str|
puts str
end
7stud probably covered your question, so if you don't mind I'd like to
hijack this thread and ask a more general question about JSON
parsing...
Is it possible that JSON could be built into Ruby? The syntax is so
close to Ruby's as of 1.9, that it seems a small step and rather a
shame not to just go ahead and make it compatible. Off hand it seems
that only quoted keys are missing.
T.
···
On Nov 23, 7:30 pm, Marko Anastasov <marko.anasta...@gmail.com> wrote:
Now, among the rest, I also want to access those "ruby", "json" and
"library" strings.
With the following code:
@structs = JSON.parse(@json_stream)
for i in 0...@structs.length @struct_obj = @structs.fetch(i) @struct_obj.each { |key, value|
if key == "t"
# get the value that 't' points to
end
}
end
I get them all appended to each other without any whitespace, ie
"rubyjsonlibrary".
#the value that t points to is stored in your 'value' variable
value.each do |str|
puts str
end
Whoops. Never mind. I'm not even sure why anyone would use the
ruby-json gem. There's no documentation anywhere, and after I installed
it, I couldn't even require it into a program without error.