开发者

parsing json with rhomobile

开发者 https://www.devze.com 2023-01-29 05:23 出处:网络
i have a json data stream at http://mdata.taviatech.com.ng/mobiledb/topgainers Can anyone give me sample code for 开发者_开发知识库to parse this to a page?

i have a json data stream at http://mdata.taviatech.com.ng/mobiledb/topgainers Can anyone give me sample code for 开发者_开发知识库to parse this to a page?

Also, is the json well formed?

thanks


When trying to parse json in Rhodes, try with Rho:JSON.parse(string) instead of JSON.parse(string). Hope That helps.


res = JSON.parse("[{\"count\":10},{\"version\":1},{\"total_count\":
5425},{\"token\": 123},{\"s\":\"RhoDeleteSource\",\"ol\":[{\"o\":
\"rho_del_obj\",\"av\":[{\"i\":55550425},{\"i\":75665819},{\"i\":
338165272},{\"i\":402396629},{\"i\":521753981},{\"i\":664143530},{\"i
\":678116186},{\"i\":831092394},{\"i\":956041217},{\"i\":
970452458}]}]}]") 

Parsing JSON response into ruby data structure.


require 'json' at the top of your controller file.

Then use Rho::AsyncHttp.get to fetch the JSON string.

In your callback parse the string like this:

$httpresult = @params['body']
$jsonresult = Rho::JSON.parse($httpresult)

BTW, if you are using JSONP you will need to strip out the callback function in the response string first.

If you are NOT using JSONP then Rho 3.3.X and higher should automatically dump the @params['body'] into a parsed JSON object for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消