【问题标题】:GET json data array within a array in Titanium在 Titanium 的数组中获取 json 数据数组
【发布时间】:2014-09-19 17:23:23
【问题描述】:

'这是我的 JSON 消息。我试图在类别下列出项目名称。在尝试此之前,我只是尝试在 Titanium 中没有类别的单个窗口中打印所有项目名称。但我的代码不起作用。'

  {
     "name" : "Nation",
      {.......
   },
   "menus" : [
   {
          "menuId" : 33,
          "menuName": "Breakfast", 
           .........{
          },
         "menuItems": [
          {
          "itemName": "Thrilled Cheese",
                "category": "Entree",
           },
           {
          "itemName": "Today's Soup - Small",
                "category": "Entree",
           },
           {
          "itemName": "Lrg. Fountain Drink",
                "category": "Entree",
           },
           {
          "itemName": "Lemon Juice",
                "category": "Entree",
           },
           ...........}
           ]
        },


       {
          "menuId" : 34,
          "menuName": "Dinner", 
           .........{
          },
         "menuItems": [
          {
          "itemName": "Sweepstakes Entry",
                "category": "Entree",
           },
           {
          "itemName": "Veggie Breakfast Burrito",
                "category": "Entree",
           },
           {
          "itemName": "Sm. Fountain Drink",
                "category": "Drink",
           },
           {
          "itemName": "Med. Fountain Drink",
                "category": "Drink",
           },
           ...........
           ]
         ]
     }

'这是我在没有类别的单个窗口中打印所有项目名称的代码'

     var json = JSON.parse(this.responseText);
    for (var i = 0; i < json.menus.length; i++) {

        for (var j = 0; j < json.menus[i].menuitems[j].lenght; j++) {  

            var row = Ti.UI.createTableViewRow({
                height: 60,
            });

            var itemLabel = Ti.UI.createLabel({
                text: json.menus[i].menuItems[j].menuItems.itemName, 
                height: 'auto',
                left:54,
                top: 5,
                font:{ fontSize:20 } 
            });

            row.add(itemLabel);
            data.push(row);

       }
    }

    tableview.setData(data);

【问题讨论】:

  • 最好给一些json数据的链接。
  • @suchit 抱歉,这是官方餐厅链接。不这样做还有什么可能吗?
  • 我会在 for 循环上放一个断点,看看您的信息是否已按您的预期构建到 json 变量中。我还会在 tableview.setData(data) 上放置一个断点并查看数据变量以查看它包含的所有行。

标签: javascript titanium


【解决方案1】:

第二个 for 循环的长度有错别字。

 for (var j = 0; j < json.menus[i].menuitems[j].lenght; j++) { 

 for (var j = 0; j < json.menus[i].menuitems[j].length; j++) { 

【讨论】:

  • 我的代码是正确的。但是为这个 tableview 页面创建 windowform 的错误。 var curtWin = Ti.UI.currentWindow;
猜你喜欢
  • 1970-01-01
  • 2015-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-02
  • 2013-02-19
相关资源
最近更新 更多