user2360274
user2360274

Reputation:

Parse JSON with Ruby

I have two JSON returns.

One I am able to parse fine

{"login"=>"foo", "id"=>bar,

with

@foobar_collect["login"]

But one I am having issues with

{"items"=>[{"user_id"=>foo, "user_type"=>"bar", 

I try

@foobar_collect["items"]["user_id"]

And it gives me an error no implicit conversion of String into Integer

What am I doing wrong?

Upvotes: 0

Views: 364

Answers (2)

pdoherty926
pdoherty926

Reputation: 10399

@foobar_collect["items"].first["user_id"]

Upvotes: 0

jvnill
jvnill

Reputation: 29599

try

@foobar_collect['items'][0]['user_id']

The reason why your code doesn't work is @foobar_collect['items'] is an array.

Upvotes: 2

Related Questions