2012-05-17 3 views
1

appcelerator 모바일 앱에서 Town 's API의 Bands 이벤트를 구문 분석하고 표시하는 데 문제가 있습니다. (iOS) 이것은 테이블에 보여주고 싶은 밴드 이벤트입니다. http://api.bandsintown.com/artists/Lucy%20Seven/events.json?api_version=2.0&app_id=LucySeven 그리고 이것은 내가 보여주는이 코드를입니다 그것을bandsintown API에서 json을 파싱합니다.

여기 JSON에 대한 API 응답이
var win = Ti.UI.currentWindow; 

win.hideNavBar(); 

Ti.UI.backgroundColor = '#050505'; 

var url = "http://api.bandsintown.com/artists/Lucy%20Seven/events.json?  api_version=2.0&app_id=LucySeven" 

var table = Ti.UI.createTableView({ 

     backgroundColor: '#050505', 
     separatorColor:'#110000', 
    }); 
var tableData = []; 
var json, artists, name, picture, title, description; 

var xhr = Ti.Network.createHTTPClient({ 
onload: function() { 
// Ti.API.debug(this.responseText); 

json = JSON.parse(this.responseText); 
for (i = 0; i < json.data.length; i++) { 
    data = json.data[i]; 
    row = Ti.UI.createTableViewRow({ 
     height:'100dp', 
     backgroundColor: '#050505', 
     separatorColor:'#110000', 
    }); 
    var name = Ti.UI.createLabel({ 
     text: title, 
     font:{ 
      fontSize:'17dp', 
     fontWeight:'bold' 
    }, 
    height:'auto', 
    left:'90dp', 
    top:'20dp', 
    color:'#eee', 
    touchEnabled:true 
    }); 
    row.add(name); 


     var start = Ti.UI.createLabel({ 
     text: description, 
     font:{ 
      fontSize:'12dp' 
     }, 
    height:'auto', 
    left:'90dp', 
    bottom:'20dp', 
    color:'#eee', 
    touchEnabled:true 
    }); 
    row.add(start); 


    // Avatar 
      var img = Ti.UI.createImageView({ 
       image : thumb_url , 
       width : 70, 
       height : 70, 
       top  : 5, 
       bottom : 5, 
       borderRadius: 5, 
       borderColor: '#eee', 
       left : 5 
      }); 
      row.add(img); 


    tableData.push(row); 
    } 

table.setData(tableData); 
}, 
onerror: function(e) { 
Ti.API.debug("STATUS: " + this.status); 
Ti.API.debug("TEXT: " + this.responseText); 
Ti.API.debug("ERROR: " + e.error); 
alert('There was an error retrieving the remote data. Try again.'); 
}, 
timeout:5000 
}); 

xhr.open("GET", url); 
xhr.send(); 

: 정말 캔트 ... 어쩌면 메신저 무엇을보고 잘못된 멀게하는 것입니다 무엇을 볼 http://www.bandsintown.com/api/responses#events-json 을 나는 놓쳤다? 누군가가 저에게 올바른 방향으로 나를 가리킬 수 있다면 고맙겠습니다. 내가 함께 시도 : data.title data.artists.title 제목 artists.titel 등 아무것도하지만 내있는 tableview에서 보여 ..... 고맙습니다 // R this.responseText의 값이 무엇

+0

그게 뭐니 뭐니해도 틀린거야? 오류가 있습니까? 오류 메시지의 정확한 텍스트와 행은 무엇입니까? –

+0

오류가 없거나 그런 것입니다. 나는 그저 아무것도 볼 수 없어요. 그것은 내 테이블에 아무것도 보여주지 않을거야. –

답변

1

JSON.parse 이후에 json의 값은 무엇입니까? JSON 응답에서 data 속성을 볼 수 없으므로 json.data이 무엇인지 잘 모르겠습니다. 또한 Ti.UI.createLabel에서 당신은 test: title하지만 title 값을 부여하지 않습니다.

json = JSON.parse(this.responseText); // `json` will be an array of objects 

for (i = 0; i < json.length; i++) { 
    data = json[ i ]; 
    // ... 

    var name = Ti.UI.createLabel({ 
    text: data.title, 
    // ... 
    }); 
} 

이 많은 디버깅과 동일 디버깅하는 키 당신은 내가했습니다 (각 단계에서 무엇을 데이터 밖으로 물건을 찾기 :

난 당신이 정말 for 루프에서 원하는 것을 의심이있다 결코 티타늄을 사용하지는 않았지만 적어도 적어도 console.log과 같은 것이 있어야합니다.) 그리고 예상과 다른 점을 파악하십시오.

+0

옙! 그 트릭을 했어! 나는 지금 보여줄 ID와 설명을 얻을 수있다! :) 나는 아직도 이름 또는 그림을 얻지 않는다. 그러나 어쩌면 그것은 단지 약간의 시간을 바보짓을하는 데 걸린다. 그리고 나는 그것을 얻을 것이다. 고맙습니다! 저예산 밴드가되어 예산없이 모든 일을하기는 쉽지 않습니다. 건배! –

+0

아티스트의 이름과 그림은 'json [i] .artists [j] .name'이어야합니다 (첫 번째는'j ', 다음은'1 '등).'.image_url ' 각기. 행운을 빕니다! –

관련 문제