我正在处理简单的任务,从 JSON 格式的 url 读取数据并在表中显示这些字段
我写的代码就像
var Win = Titanium.UI.currentWindow;
//SEARCH BAR
var xhr = Titanium.Network.createHTTPClient();
tableData=[];
Win.open();
xhr.onload = function() {
alert('res'+this.responseData);
var json = this.responseText;
var response = JSON.parse(json);
//-- Mail was sent
alert('respoinse length : '+response.result.length);
tableData=[];
for (i = 0; i < response.result.length; i++) {
sresult = response.result[i];
//alert('City'+ sresult.city);
var row = Ti.UI.createTableViewRow({
rowID: i,
color:'#222',
left:70, top:44,
width:360,
text:sresult.County
});
tableData.push(row);
}
table.setData(tableData);
};
var table = Titanium.UI.createTableView({
top:60,
data:tableData
});
Win.add(table);
//xhr.open('GET', 'https://www.clia.livestockid.ca/CLTS/public/division/CCIA/en/splash_logo.jpg');
xhr.open('GET', 'http://gomashup.com/json.php?fds=geo/usa/zipcode/city/STERLING');
xhr.send();
我在 Titanium 上运行它——显示 JSON 数据的第一个警报。之后它没有得到第二个不确定的警报......为什么它不进入下一步......请帮助我解决代码中的任何错误或解析问题。
谢谢德文达