【问题标题】:JSON deserialize with Javascript - Titanium Appcelerator使用 Javascript 反序列化 JSON - Titanium Appcelerator
【发布时间】:2014-07-21 20:55:17
【问题描述】:

我正在使用 Titanium 调用一个 API,该 API 使用格式如下的 JSON 进行响应:

{
 "1":{"id":"4","field1":"Name 1","ordering":"1"},
 "2":{"id":"6","field1":"Name 2","ordering":"2"},
 "3":{"id":"7","field1":"Name 3","ordering":"3"},
 "4":{"id":"5","field1":"Name 4","ordering":"4"}
}

我想用这样的代码迭代这个答案:

json = JSON.parse(this.responseText);
for (var i=0; i<json.length; i++) {
          //Something here with json[i];
          }

此代码未执行,因为 json.length 不是有效值。

如何在不更改服务器端 JSON 的情况下解决?

【问题讨论】:

    标签: javascript json titanium


    【解决方案1】:

    使用for in 循环遍历对象中的每个属性:

    for (var i in json)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-03
      • 2011-09-05
      • 2016-12-30
      • 2019-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多