Search code examples
jsonruby-on-rails-3parsingtitaniumappcelerator

Parsing Rails JSON in Titanium?


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


Solution

  • 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?