0

I have data in this format:

{"values"=>
[
{"updateKey"=>"UNIU-16268324-5608633092144111616-SHARE", 
"updateComments"=>{"_start"=>1, 
"values"=>[{"comment"=>"Sample test this is mike testing.", 
  "person"=>{"siteStandardProfileRequest"=>{"url"=>"http://www.linkedin.com/profile?viewProfile=&key=116654056&authToken=xVLh&authType=name&trk=api*a140290*s148640*"}, 
  "lastName"=>"DeLorenzo", 
  "headline"=>"--", 
  "id"=>"QM86-RIKjb", 
  "pictureUrl"=>"http://media.linkedin.com/mpr/mprx/0_OurBLnHMma92b4U4pecXLq2MuW8aFOo4ywXHLqEbPuNO4sjZtEhUwNOWCFhAkJIq07-WoP4V_Zqg", "firstName"=>"Jennifer", 
  "apiStandardProfileRequest"=>{"url"=>"http://api.linkedin.com/v1/people/QM86-RIKjb",     "headers"=>{"values"=>
[{"name"=>"x-li-auth-token", 
"value"=>"name:xVLh"}], 
"_total"=>1}}}, 
"timestamp"=>1337202768000, 
"sequenceNumber"=>1, 
"id"=>80942976}, 
{"comment"=>"123", 
"person"=>{"siteStandardProfileRequest"=>{"url"=>"http://www.linkedin.com/profile?viewProfile=&key=70292133&authToken=wEAo&authType=name&trk=api*a140290*s148640*"}, "lastName"=>"Kartsovnyk", "headline"=>"Snr Software Developer", "id"=>"7-32mNn-Ob", "pictureUrl"=>"http://media.linkedin.com/mpr/mprx/0_xjj5WPXU6fCjCExLjUa9WA69XWNS

What I am trying to do is to loop through the updateComments and get each "id" attribute for that user.

Here is what I have so far:

if linked_in_updates.values.updateComments.is_a?(Hash)   
  linked_in_updates.each { |key, value|
    some_value = key
  }
end

I am trying to extract the hash which is the updateComments with this: linked_in_updates.values.updateComments but I get the error like this:

NoMethodError: undefined method `updateComments' for #<Array:0x13228fc20>

Any idea what I am doing wrong?

2
  • 1
    That looks like JSON with literal \n rather than linebreaks Commented May 29, 2012 at 14:27
  • @Michael would that make an impact on how I extract the values? Commented May 29, 2012 at 14:35

1 Answer 1

1

try to replace

linked_in_updates.values.updateComments.is_a?(Hash)

with

linked_in_updates.values[0]['updateComments'].is_a?(Hash)  
Sign up to request clarification or add additional context in comments.

6 Comments

thanks! Could you please exaplain to me why the syntax is values[0]['updateComments'] ? I am not sure how it was a 2-d array. I'll accept the answer when SO allows me.
btw also I get the error: TypeError: can't convert String into Integer after I try your suggestions.
add Rails.logger.info linked_in_updates.values[0] before if linked_in_updates.values.updateComments.is_a?(Hash) then run tail -f log/development.log
Actually that is the line that gives the error: TypeError: can't convert Array into String :)
I just updated the data that comes in. Maybe it makes a difference.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.