0
티타늄 날씨 프로젝트에서 json 데이터를 구문 분석하고 프로젝트에서 데이터를 표시하려고하지만 할 수 없습니다. 나는 열심히 노력하고 있지만 계속 실패하고 있습니다.json 데이터를 표시하는 방법
여기 내 코드는 무엇입니까? 아무도 도와주세요.
var win = Titanium.UI.createWindow({
backgorundColor: '#000',
title: 'My Weather App'
});
var tableview = Ti.UI.createTableView();
var data = [];
var xhr = Ti.Network.createHTTPClient({
onload: function() {
alert("success!");
var json = JSON.parse(this.responseText);
for (var i = 0; i < json.observation_location.length; i++) {
//data.push({"country":json.observation_location[i].country,"city":json.observation_location[i].city});
var row = Ti.UI.createTableViewRow({
height: 60,
//filter:observation_location[i].
});
var countryLabel = Ti.UI.createLabel({
text: json.observation_location[i].country,
height: 'auto',
left: 10,
top: 5,
});
var cityLabel = Ti.UI.createLabel({
text: json.observation_location[i].city,
height: 'auto',
left: 15,
});
row.add(countryLabel);
row.add(cityLabel);
data.push(row);
}
tableview.setData(data);
},
onerror: function() {
alert('There was an error retrieving the remote data. Try again.');
}
//timeout:5000
});
xhr.open("GET", "http://api.wunderground.com/api/02e5dd8c34e3e657/geolookup/conditions/forecast/q/Dhaka,Bangladesh.json");
xhr.send();
win.add(tableview);
win.open();
감사합니다. – user3476498