qt代码到json转换

时间:2014-11-15 20:53:28

标签: java json qt

我有很多qt,我想转换为Json代码 这个代码大多像:

ApplicationWindow {
title: qsTr("Hello World")
width: 640
height: 480

menuBar: MenuBar {
    Menu {
        title: qsTr("File")
        MenuItem {
            text: qsTr("&Open")
            onTriggered: console.log("Open action triggered");
        }
        MenuItem {
            text: qsTr("Exit")
            onTriggered: Qt.quit();
        }
    }
}

Button {
    text: qsTr("Hello World")
    anchors.horizontalCenter: parent.horizontalCenter
    anchors.verticalCenter: parent.verticalCenter
}}

此代码是用户界面代码我想将其转换为Json代码我尝试艺术编码方式,但我没有一个好的结果,在Java或网站有一个库来做到这一点?

1 个答案:

答案 0 :(得分:0)

手动翻译大多是直截了当的:

{
    "title": "Hello World",
    "width": 640,
    "height": 480,

    "menuBar": {
        "Menu": {
            "title": "File",
            "MenuItem": [{
                "text": "&Open",
                "onTriggered": "Open action triggered" <=== Possibly some further structure here
            },
            {
                "text": "Exit",
                "onTriggered": ???? <=== Not clear what should be here
            }
        }
    },

    "Button": {
        "text": "Hello World",
        ===> "anchors" could be a single JSON object with two elements <===
        "anchors.horizontalCenter": "parent.horizontalCenter" <=== Use numeric or character constant
        "anchors.verticalCenter": "parent.verticalCenter" <=== Ditto
    }
}

请注意,类型信息会丢失 - 需要进行推断或明确包含。<​​/ p>