0

以下のjson形式をそれぞれのjson形式に変換したい。Rest サービスから受け取った Json は設計をサポートしていません。以下のリスト ビューを実装するのに疲れました。

http://www.oracle.com/webfolder/technetwork/jet/jetCookbook.html?component=listView&demo=jsonHierListView

JSON 形式 (Rest サービスから受け取ります)

{
  "ActionHistory": [{
      "id": "action",
      "name": "Action History",
      "children": [{
        "childrenItem": {
          "id": "action1",
          "type": "fa fa-info",
          "empId": "101",
          "ActionDate": "on 18-Apr-2017 18:20:32",
          "Action": "Submit",
          "From": "Deb Raphaely",
          "To": "Neena Kochlar",
          "pic": "deb_avatar",
          "Details": ""
        }
      }, {
        "childrenItem": {
          "id": "action2",
          "type": "fa fa-info",
          "empId": "101",
          "ActionDate": "on 19-Apr-2017 18:20:32",
          "Action": "Approve",
          "From": "Neena Kochlar",
          "To": "James",
          "pic": "neena_avatar",
          "Details": ""
        }
      }]
    },
    {
      "id": "action",
      "name": "Action History2",
      "children": [{
        "childrenItem": {
          "id": "action1",
          "type": "fa fa-info",
          "empId": "101",
          "ActionDate": "on 18-Apr-2017 18:20:32",
          "Action": "Submit",
          "From": "Deb Raphaely",
          "To": "Neena Kochlar",
          "pic": "deb_avatar",
          "Details": ""
        }
      }, {
        "childrenItem": {
          "id": "action2",
          "type": "fa fa-info",
          "empId": "101",
          "ActionDate": "on 19-Apr-2017 18:20:32",
          "Action": "Approve",
          "From": "Neena Kochlar",
          "To": "James",
          "pic": "neena_avatar",
          "Details": ""
        }
      }]
    }
  ]
}

必要な JSON 形式

{
  "ActionHistory": [

    {
      "attr": {
        "id": "action",
        "name": "Action History"
      },
      "children": [{
          "attr": {
            "id": "action1",
            "type": "fa fa-info",
            "empId": "101",
            "ActionDate": "on 18-Apr-2017 18:20:32",
            "Action": "Submit",
            "From": "Deb Raphaely",
            "To": "Neena Kochlar",
            "pic": "deb_avatar",
            "Details": ""
          }
        },
        {
          "attr": {
            "id": "action2",
            "type": "fa fa-info",
            "empId": "101",
            "ActionDate": "on 19-Apr-2017 18:20:32",
            "Action": "Approve",
            "From": "Neena Kochlar",
            "To": "James",
            "pic": "neena_avatar",
            "Details": ""
          }
        }

      ]
    }, {
      "attr": {
        "id": "action",
        "name": "Action History"
      },
      "children": [{
          "attr": {
            "id": "action1",
            "type": "fa fa-info",
            "empId": "101",
            "ActionDate": "on 18-Apr-2017 18:20:32",
            "Action": "Submit",
            "From": "Deb Raphaely",
            "To": "Neena Kochlar",
            "pic": "deb_avatar",
            "Details": ""
          }
        },
        {
          "attr": {
            "id": "action2",
            "type": "fa fa-info",
            "empId": "101",
            "ActionDate": "on 19-Apr-2017 18:20:32",
            "Action": "Approve",
            "From": "Neena Kochlar",
            "To": "James",
            "pic": "neena_avatar",
            "Details": ""
          }
        }

      ]
    }
  ]
}

JSON 形式を変換するのに疲れましたが、長さ = 1 の JSON 配列ではうまくいきました。配列の長さを大きくすると、うまくいきません。ここに私のコードがあり ます https://jsfiddle.net/72mz5zft/

4

1 に答える 1