我部分成功地将 json 解析为我的 qml 应用程序,但只是部分成功。我可以通过 console.log() 很好地输出 countryCode 和 countryName,最终目标仍然是将 json 解析的数据附加到 listmodel。仍然无法输出带有年份和实际数据数据部分的 bigmac_index。
显然已经尝试了不同的解决方案并尝试应用主题的给定答案,但没有成功。希望从工作解决方案中受益:)
json 部分: [ { "countryCode": "fi", "countryName": "Finland", "bigmac_index": [ { "year": "2013", "data": "5.27" }, { "year": " 2012", "data": "4.55" }, { "year": "2011", "data": "5.38" } ] } ]
这是我正在使用的功能:
function request(url, callback) {
var xhr = new XMLHttpRequest();
console.log("xhr.send executed")
xhr.onreadystatechange = (function()
{
console.log("xhr readystate ", xhr.readyState)
if(xhr.readyState == 4 && xhr.status == 200)
{
console.log("readyState == 4, starting to …Run Code Online (Sandbox Code Playgroud)