从给定的层次结构级别对象列表生成子数组json

时间:2017-07-21 11:39:15

标签: json

"questionnaireData": [

    {
      "questionaireType": "Q_AUTO_APPLICATION",
      "cardID": "<blank>",
      "setID": "<blank>",
      "setName": "<blank>",
      "sectionID": "<blank>",
      "sectionName": "<blank>",
      "pageID": "Person",
      "fieldName": "LASTNAME",
      "content": "Steve",
      "fieldCode": "1111"
    },
    {
      "questionaireType": "Q_AUTO_APPLICATION1",
      "cardID": "Card 1",
      "setID": "<blank>",
      "setName": "<blank>",
      "sectionID": "<blank>",
      "sectionName": "<blank>",
      "pageID": "Person",
      "fieldName": "LASTNAME",
      "content": "Steve",
      "fieldCode": "1111"
    }
    ]

以上JSON数组显示2个对象(样本列表),每个对象具有相同顺序的字段集。这意味着,第一个节点(questionaireType)处于根级别。 对于其他字段,如果父节点值不是<blank>,则先前的值应作为父节点引用。如果父节点为<blank>,则应转到不是<blank>的下一个父节点。

下面,我在每行添加了注释以供解释。 请帮我生成JSON对象,以便在角树中使用以下类型的列表(这意味着我需要从此列表中生成嵌套的子json数组)。

   "questionaireType": "Q_AUTO_APPLICATION",  // root parent

  "cardID": "<blank>",           // should not consider as value is <blank> 

  "setID": "2",                  // should display as root parent's child as 
                                 //  cardID is blank

  "setName": "SET1",             // setID & setName are in same object
  "sectionID": "<blank>",        //should not consider as value is <blank>
  "sectionName": "<blank>",      //should not consider as value is <blank>
  "pageID": "Person",            //pageID should come under setID as 
                                 //sectionID is <blank>
  "fieldName": "FIRSTNAME",      //fieldName,content & fieldCode are in same 
                                 //object and come under pageID
  "content": "John",
  "fieldCode": "1111"

0 个答案:

没有答案