私はqml applにjsonを構文解析することで部分的に成功していますが、部分的にしかありません。私はcountryCodeとcountryNameをconsole.log()経由で出力することができますが、endターゲットはjsonの解析データをlistmodelに追加します。 bigmac_indexには年と実際のデータのデータ部分を出力できません。listmodelにjsonを構文解析する
明らかに別の解決策を試してみて、被験者の回答を適用しようとしましたが、失敗しました。ワーキング溶液から感謝:)
JSON一部: [ { "国番号": "Fiの"、 "COUNTRYNAME": "フィンランド"、 "bigmac_index":[ { "年": " 2013" 、 "データ": "5.27" }、 { "年": "2012"、 "データ": "4.55" }、 { "年": "2011"、 「データ":" 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 parse")
var parseData = JSON.parse(xhr.responseText);
for (var index in parseData)
{
console.log("countrycode, ", parseData[index].countryCode)
console.log("countryName, ", parseData[index].countryName)
console.log("datakey, ", parseData[index].bigmac_index)
//Attemp to parse to ListModel
lmodel.append
({
"countryCode" : parseData.countryCode,
"countryName" : parseData[index].countryName,
"datakey" : parseData[index].bigmac_index
})}
}
else
{
console.log("readyState, ", xhr.readyState)
}
}
);
xhr.open('GET', url, true);
xhr.send();
}
JSON構造+ APIデータ: http://blog.inqubu.com/inqstats-open-api-published-to-get-demographic-data
Thxを、あなたの応答に基づいて調整コード。 – JRii
この作業ができました。問題の解決方法を覚える必要があります:) – JRii