如何在黑莓10中使用qml访问嵌套的数组JSON文件
问题描述:
我有下面的json文件我想从上面访问时间,百分比,数量嵌套数组JSON文件使用Qml。我无法获得这些数据。我想要这些数据填写一个有3列的表格。请告诉我该怎么做。 如何在黑莓10中使用qml访问嵌套的数组JSON文件
sample.json:
{
"rates": [
{
"time": "3 Months",
"interest": [
{
"percent": "0.01",
"amount": "2500"
},
{
"percent": "0.02",
"amount": "5000"
},
{
"percent": "0.09",
"amount": "10000"
}
]
},
{
"time": "6 Months",
"interest": [
{
"percent": "0.10",
"amount": "2500"
},
{
"percent": "0.11",
"amount": "5000"
},
{
"percent": "0.12",
"amount": "10000"
}
]
},
{
"time": "1 Year",
"interest": [
{
"percent": "0.11",
"amount": "2500"
},
{
"percent": "0.12",
"amount": "5000"
},
{
"percent": "0.14",
"amount": "10000"
}
]
}
]
}
答
这是你如何加载和获取数据。如何在一个表中获取不应该是很难从这里
import bb.cascades 1.2
import bb.data 1.0
Page {
Container {
}
attachedObjects: [
DataSource {
id: dataSource
source: "sample.json"
type: DataSourceType.Json
onDataLoaded: {
console.log(data.rates);
console.log(JSON.stringify(data));
for(var i = 0; i < data.rates.length; i++){
console.log(JSON.stringify(data.rates[i]));
console.log("Time: " + data.rates[i].time);
for(var j =0; j < data.rates[i].interest.length; j++)
{
console.log(JSON.stringify(data.rates[i].interest[j]));
console.log("Percent: " + data.rates[i].interest[j].percent);
console.log("Amount: " + data.rates[i].interest[j].amount);
}
}
}
}
]
onCreationCompleted: {
dataSource.load();
}
}
其工作正常,但我想在一个容器内写那么它会在模拟器 – xxxxxx 2014-09-19 13:04:37
显示我如何使用CPP访问上面的JSON文件 – xxxxxx 2014-09-24 10:43:01