i am trying to parse a JSON structure into a database using rhonobile and my code is below;
def GetTopGainers
Rho::AsyncHttp.get(
:url => 'http://www.xyz.com/xyz',
:callback => (url_for :action => :httpget_callback),
:callback_param => "" )
redirect :action => :viewhttp
end
def httpget_callback
$httpresult = @params['body'][0].inspect
@params['body'].each do |dailygainers|
mygainer = Topgainers.new
mygainer.gainers = Topgainers["dailygainers"]["gainers"]
mygainer.date = Topgainers["dailygainers"]["date"]
mygainer.open = Topgainers["dailygainers"]["Open"]
mygainer.close = Topgainers["dailygainers"]["Close"]
mygainer.save
end
WebView.refresh
end
The problem is that nothing is bei g saved to the database.
Any ideas?
If your web service is not setting the proper headers, you may be getting string data back instead of json data. You would use JSON.parse(@params['body']) to convert the string to json.
Attaching the rholog.txt would help to see if this is the case.