在 Titanium 中解析 Rails JSON?
我正在关注 使用 JSON 构建 Twitter 客户端教程,但我尝试从我自己的 Rails API 而不是 Twitter 获取数据。我的 JSON 生成如下:
[ { "name":"Some Text", "created_at":"2011-05-15T15:33:37Z", "id":1, "image": { "url":"/uploads/image/1/2611c0.jpg", "thumb": { "url":"/uploads/image/1/thumb_2611c0.jpg" } }, "updated_at":"2011-05-15T15:33:37Z" }, { "name":"Some More Text", "created_at":"2011-05-15T15:43:37Z", "id":2, "image": { "url":"/uploads/image/2/2756c0.jpg", "thumb": { "url":"/uploads/image/2/thumb_2756c0.jpg" } }, "updated_at":"2011-05-15T15:43:37Z" } ]
当我尝试解析该数组然后循环遍历它时,我收到看似无穷无尽的控制台消息:
[WARN] [object TiUIView] has an auto height value of 0, meaning this view may not be visible.
据我所知,这意味着由于解析问题,数组为空。为了进行测试,我在视图中创建了一个简单的标签并传递了原始 JSON 对象。它显示正确,因此 Rails 正在完成其工作。感谢您的任何建议!
编辑按照要求的Ti代码:http://pastie.org/1928676
I am following the Using JSON to Build a Twitter Client tutorial, but I am trying to GET data from my own Rails API rather than Twitter. My JSON is being generated as follows:
[ { "name":"Some Text", "created_at":"2011-05-15T15:33:37Z", "id":1, "image": { "url":"/uploads/image/1/2611c0.jpg", "thumb": { "url":"/uploads/image/1/thumb_2611c0.jpg" } }, "updated_at":"2011-05-15T15:33:37Z" }, { "name":"Some More Text", "created_at":"2011-05-15T15:43:37Z", "id":2, "image": { "url":"/uploads/image/2/2756c0.jpg", "thumb": { "url":"/uploads/image/2/thumb_2756c0.jpg" } }, "updated_at":"2011-05-15T15:43:37Z" } ]
When I try to parse this array and then loop through it, I get this seemingly endless console message:
[WARN] [object TiUIView] has an auto height value of 0, meaning this view may not be visible.
As far as I can tell, this means that the array is empty, due to a parsing problem. To test, I created a simple label in my view and passed the original JSON object. It displayed correctly, so Rails is doing its job. Thanks for any suggestions!
EDIT Ti code as requested: http://pastie.org/1928676
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测,当您进行测试时,您没有将
row.height
设置为'auto'
吗?通过将row.height
设置为'auto'
,然后添加height
为'auto'< 的子视图/code> 您还为其指定了
height
为0
,如上面的警告所述。我会尝试给row.height
一些除 auto 以外的东西,看看你能用它做什么?I'm going to take a guess and say that when you did you're test you didn't set the
row.height
to'auto'
? By setting therow.height
to'auto'
and then it's child view that you add with aheight
of'auto'
also you are assigning it aheight
of0
like the warning above states. I would play around with giving therow.height
something other then auto and see what you can do with that?