-1

I have the following json file I am trying to access time, percent, amount from above nested array Json file using Qml. I am not able to get these data. I want this data to fill in a table which has 3 columns. Please tell me how to do it.

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"
        }
      ]
    }
  ]
}
Sébastien
  • 11,860
  • 11
  • 58
  • 78
xxxxxx
  • 1
  • 1

1 Answers1

0

This is how you load and get the data. How to get in a table shouldn't be that hard from here

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();
    }
}
Bojan Kogoj
  • 5,321
  • 3
  • 35
  • 57