Access only one attribute of API in response - Ruby on Rails 4 -
i calling api returns array of json objects , can access return values of api call
[{"param1":1,"param2":"blah1"}, {"param1":2,"param2":"blah2"}, {"param1":3,"param2":"blah3"}]
i know can access each param1 through iteration or static indexing @client[0].param1
@client[1].param1
@client[2].param1
thing , don't want param2 , want param1 . there way , access param1 without iteration or static indexing below result in response
[{"param1":1}, {"param1":2}, {"param1":3}]
update
the thing notice want filter result while making request (before getting response when know attribute name)
try use delete
.
deletes , returns key-value pair hsh key equal key. if key not found, returns default value. if optional code block given , key not found, pass in key , return result of block.
data = [{"param1":1,"param2":"blah1"}, {"param1":2,"param2":"blah2"}, {"param1":3,"param2":"blah3"}] data.each {|x| x.delete("param2")}
for more information delete. hope you.
Comments
Post a Comment