LOOP ARRAY OF HASHES

18 views
Skip to first unread message

Simon Eric

unread,
Jun 16, 2015, 12:26:33 PM6/16/15
to rubyonra...@googlegroups.com
Please how can i loop this to have all values of _id, contact, sent,
answer, repondant?

{
"result" : [
{
"_id" : null,
"contact" : 45684,
"sent" : 0,
"answer" : 0,
"repondant" : 0
},
{
"_id" : "vms",
"contact" : 6340,
"sent" : 6340,
"answer" : 0,
"repondant" : 0
},
{
"_id" : "sms",
"contact" : 27356,
"sent" : 41344,
"answer" : 0,
"repondant" : 0
}
],
"ok" : 1
}


Thank you very much

--
Posted via http://www.ruby-forum.com/.

amtest

unread,
Jun 16, 2015, 1:53:39 PM6/16/15
to rubyonra...@googlegroups.com
Might be you can use like this way the JSON

  json = JSON.parse(value)
    json["result"].each do |item|
    # do something
  end

Colin Law

unread,
Jun 16, 2015, 1:55:18 PM6/16/15
to rubyonra...@googlegroups.com

Which bit don't you know how to do? Access the result array, iterate the array, access the individual elements, or print the values?

Colin

>
> --
> Posted via http://www.ruby-forum.com/.
>

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/effbb0e610963e6d58151176875dae4b%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages