zoukankan      html  css  js  c++  java
  • QML JSON 展示

    1 import QtQuick 1.0
    2
    3 Rectangle {
    4 600
    5 height: 400
    6
    7 Rectangle {
    8 id: topInput
    9 height: 20; parent.width;
    10 anchors.top: parent.top;z:2;
    11
    12 Rectangle {
    13 id: jsonTxt
    14 border.color: "black"; border. 1
    15 parent.width - 50; height: 20;
    16
    17 TextInput {
    18 id: textContent;
    19 parent.width;
    20 anchors.left: parent.left;
    21 anchors.verticalCenter: parent.verticalCenter;
    22 text: "{\"name\":\"gibbon\",\"age\":18,\"work\":{\"locate\":\"Beijing\",\"content\":\"progammer\"}}"
    23 }
    24 }
    25
    26 Rectangle {
    27 border.color: "black"; border. 1
    28 40; height: 20; color: "red"
    29 anchors.left: jsonTxt.right; anchors.leftMargin: 5;
    30
    31 Text {
    32 text: "Click";
    33 anchors.centerIn: parent;
    34 }
    35
    36 MouseArea {
    37 anchors.fill: parent;
    38 onClicked: {
    39 console.log("do the work````");
    40 doTheWork(textContent.text)
    41 }
    42 }
    43 }
    44 }
    45
    46 Rectangle {
    47 id: bottomOutput
    48 parent.width; height: parent.height-topInput.height-5;
    49 color: "white"; anchors.bottom: parent.bottom;
    50
    51 ListView {
    52 id: dataShow;
    53 parent.width; height: parent.height;
    54 model: dataSource;
    55 delegate: Component {
    56 id: theDelegate;
    57 Item {
    58 200; height: 30
    59 Row {
    60 spacing: 10
    61 200; height: 30
    62 Text { text: path; color: "red" }
    63 Text { text: type; color: "blue" }
    64 Text { text: value; color: "black" }
    65 }
    66 }
    67 }
    68
    69 ListModel {
    70 id: dataSource
    71 }
    72
    73 }
    74 }
    75
    76
    77
    78 function getJsonContent(path, obj) {
    79 for(var p in obj) {
    80 if(typeof(obj[p])==="object") {
    81 dataSource.append({path:path+"."+p,type:typeof(obj[p]),value:"OBJECT"});
    82 getJsonContent(path+"."+p,obj[p]);
    83 } else {
    84 dataSource.append({path:path+"."+p,type:typeof(obj[p]),value:obj[p]});
    85 }
    86 }
    87 }
    88
    89 function doTheWork(str) {
    90 console.log(str);
    91 var jsonObj=eval("("+str+")");
    92
    93 if(jsonObj) {
    94 dataSource.clear();
    95 getJsonContent("obj",jsonObj);
    96 }
    97
    98 }
    99 }

  • 相关阅读:
    LightOJ 1132 Summing up Powers(矩阵快速幂)
    hdu 3804 Query on a tree (树链剖分+线段树)
    LightOJ 1052 String Growth && uva 12045 Fun with Strings (矩阵快速幂)
    uva 12304 2D Geometry 110 in 1! (Geometry)
    LA 3263 That Nice Euler Circuit (2D Geometry)
    2013 SCAUCPC Summary
    poj 3321 Apple Tree (Binary Index Tree)
    uva 11796 Dog Distance (几何+模拟)
    uva 11178 Morley's Theorem (2D Geometry)
    动手动脑
  • 原文地址:https://www.cnblogs.com/gibbon/p/2038742.html
Copyright © 2011-2022 走看看