Last active
September 3, 2020 11:14
-
-
Save thecompez/6fc07782c6043ebe32c4a2c5772f283e to your computer and use it in GitHub Desktop.
JSON example in QML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myData = [{ | |
id: 1, | |
name: "Kambiz", | |
family: "Asadzadeh" | |
}, | |
{ | |
id: 2, | |
name: "Sorush", | |
family: "Rabiei" | |
}, | |
{ | |
id: 3, | |
name: "Hamed", | |
family: "Masafi" | |
}, | |
{ | |
id: 4, | |
name: "Hadi", | |
family: "Abbasi" | |
} | |
]; | |
console.log("MyData : " + JSON.stringify(myData)) | |
for (var i = 0; i < myData.length; i++) { | |
var obj = myData[i]; | |
console.log("ID : " + obj.id) | |
console.log("Name : " + obj.name) | |
console.log("Family : " + obj.family) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.15 | |
import QtQuick.Window 2.15 | |
Window { | |
width: 640 | |
height: 480 | |
visible: true | |
title: qsTr("Hello JSON World!") | |
property | |
var myData: [{ | |
id: 1, | |
name: "Kambiz", | |
family: "Asadzadeh" | |
}, | |
{ | |
id: 2, | |
name: "Sorush", | |
family: "Rabiei" | |
}, | |
{ | |
id: 3, | |
name: "Hamed", | |
family: "Masafi" | |
}, | |
{ | |
id: 4, | |
name: "Hadi", | |
family: "Abbasi" | |
} | |
] | |
Component.onCompleted: { | |
console.log("MyData : " + JSON.stringify(myData)) | |
for (var i = 0; i < myData.length; i++) { | |
var obj = myData[i]; | |
console.log("ID : " + obj.id) | |
console.log("Name : " + obj.name) | |
console.log("Family : " + obj.family) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment