使用 rhomobile 解析 json

发布于 2024-10-05 16:34:50 字数 211 浏览 0 评论 0原文

我有一个 json 数据流 http://mdata.taviatech.com.ng/mobiledb/topgainers< /a> 谁能给我示例代码来将其解析为页面?

另外,json格式正确吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘落散花 2024-10-12 16:34:50

当尝试在 Rhodes 中解析 json 时,请尝试使用 Rho:JSON.parse(string) 而不是 JSON.parse(string)。希望有帮助。

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

故事还在继续 2024-10-12 16:34:50
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}]}]}]") 

将 JSON 响应解析为 ruby​​ 数据结构.

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.

梦冥 2024-10-12 16:34:50

需要在控制器文件顶部添加“json”。

然后使用 Rho::AsyncHttp.get 获取 JSON 字符串。

在回调中,像这样解析字符串:

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

顺便说一句,如果您使用 JSONP,则需要首先删除响应字符串中的回调函数。

如果您不使用 JSONP,那么 Rho 3.3.X 及更高版本应该自动将 @params['body'] 转储到已解析的 JSON 对象中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文