2013-04-11 52 views
0

我想解析Titanium中的多維數組。Titanium應用程序中的JSON解析(多維數組)

它是這樣的: -

{"nodes": 
    [{"node": 
     { 
     "title":"<a href=\"\/adf\/into-the-blue\">Into the Blue<\/a>", 
     "Teaser":"Into the Blue Teaser.", 
     "Knowledge":"<a href=fsdf">Americas<\/a>", 
     ... 
     ... 

這就是我所做的。 (只得到第一行:()

// URL具有JSON URL。

var xhr = Titanium.Network.createHTTPClient(); 
xhr.onload = function() { 
    var response = xhr.responseText; 
    var resultObj = JSON.parse(response); 
    Ti.API.log("The Response is " + response); 
    Ti.API.log("THE RESULT " + resultObj); 
    updateBanners(resultObj); 
    updateTable(resultObj, catid, catregion, cattopic, listByDate); 
}; 
xhr.open("GET", url); 
xhr.send(); 

非常感謝

+0

如果調試應用程序並在var resultObj = JSON.parse(response);然後在調試器的觀察窗口中查看結果,它是否顯示所有數據?你確定問題出在JSON上嗎,而不是你的updateBanners()和updateTable()函數? – Martin 2013-04-11 17:15:58

回答

0

這就是我能夠解決這個問題的方法。

//Correct Response. Gives the total number of returned Records. 
resultObj.nodes.length 

// and for a specific title of first row. 

resultObj.nodes[0].node["title"] 

alert("Total Records are :- "+ responseObjArr.nodes.length + " and the 1st Title is:- " + responseObjArr.nodes[0].node["title"]); 
0

也許你缺少從解析了一塊。

礦通常看起來像。

var resultObj = JSON.parse(response).NameOfMyRemoteFunctionResult; 

我爲我的呼叫使用WCF Web服務,所以這是我回來的響應類型。