在 Titanium 中解析 Rails JSON?

发布于 2024-11-09 05:47:31 字数 1219 浏览 0 评论 0原文

我正在关注 使用 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 技术交流群。

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

发布评论

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

评论(1

雨后咖啡店 2024-11-16 05:47:31

我猜测,当您进行测试时,您没有将 row.height 设置为 'auto' 吗?通过将 row.height 设置为 'auto',然后添加 height'auto'< 的子视图/code> 您还为其指定了 height0,如上面的警告所述。我会尝试给 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 the row.height to 'auto' and then it's child view that you add with a height of 'auto' also you are assigning it a height of 0 like the warning above states. I would play around with giving the row.height something other then auto and see what you can do with that?

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