Parsing multiple JSON requests in Ruby -
i'm trying parse multiple json objects in ruby.
def processkey(key) obj = getjsondata(key) puts "got log: " + obj.to_s + "\n" @data = json.parse(obj) end
i can see obj getjsondata correct everytime, json.parse keeps on returning first object parsed
for example:
for key1 -> getjsondata(key1) returns obj1 -> json.parse(obj1) returns hash1 key2 -> getjsondata(key2) returns obj2 -> json.parse(obj2) returns hash1 key3 -> getjsondata(key3) returns obj3 -> json.parse(obj3) returns hash1
why? looking around @ http://www.ruby-doc.org/stdlib-1.9.3/libdoc/json/rdoc/json.html , stackoverflow examples don't notice way clean json memory or need other exmaples.
what doing wrong in regards json.parse? note, i'm using ruby on rail 1.9.3 -thanks, niru
found mistake in code. had accidentally left data @data, incorrect since had done refactoring. correct code within method should've been:
def processkey(key) obj = getjsondata(key) data = json.parse(obj) return data end
since @data should not instance variable , should not declared way.
-thanks, niru
Comments
Post a Comment