How to query critical JSON into ionic

Hi,

I received the JSON response from the server mentioned below.

{
  "employeeId": null,
  "id": "DB06442E-2993-4FE8-B496-5A0CF61C8342",
  "message": null,
  "objects": [
    {
      "Children": [],
      "Fields": [
        {
          "Key": "CallID",
          "Value": 1000
        },
        {
          "Key": "CallDate",
          "Value": "Sep 9 2016 10:14AM"
        },
        {
          "Key": "ClientName",
          "Value": ""
        },
        {
          "Key": "AssetName",
          "Value": "Automatic Cold Cranking Simulator"
        },
        {
          "Key": "CallCategory",
          "Value": "Corrective Maintenance"
        }
      ],
      "Type": 8
    },
    {
      "Children": [],
      "Fields": [
        {
          "Key": "CallID",
          "Value": 1000
        },
        {
          "Key": "CallDate",
          "Value": "Sep 9 2016 10:20AM"
        },
        {
          "Key": "ClientName",
          "Value": ""
        },
        {
          "Key": "AssetName",
          "Value": "Auto Mini Pour Point Tester "
        },
        {
          "Key": "CallCategory",
          "Value": "Preventive Maintenance"
        }
      ],
      "Type": 8
    },
    {
      "Children": [],
      "Fields": [
        {
          "Key": "CallID",
          "Value": 1000
        },
        {
          "Key": "CallDate",
          "Value": "Sep 9 2016 10:23AM"
        },
        {
          "Key": "ClientName",
          "Value": ""
        },
        {
          "Key": "AssetName",
          "Value": "Balance - Citizon CX 220"
        },
        {
          "Key": "CallCategory",
          "Value": "Calibration"
        }
      ],
      "Type": 8
    },
    {
      "Children": [],
      "Fields": [
        {
          "Key": "CallID",
          "Value": 1001
        },
        {
          "Key": "CallDate",
          "Value": "Sep 9 2016 10:26AM"
        },
        {
          "Key": "ClientName",
          "Value": ""
        },
        {
          "Key": "AssetName",
          "Value": "Others"
        },
        {
          "Key": "CallCategory",
          "Value": "Installation"
        }
      ],
      "Type": 8
    }
  ],
  "success": true
}

In this, I need to populate ion-items for each Fields like below:

"Fields": [
            {
              "Key": "CallID",
              "Value": 1001
            },
            {
              "Key": "CallDate",
              "Value": "Sep 9 2016 10:26AM"
            },
            {
              "Key": "ClientName",
              "Value": ""
            },
            {
              "Key": "AssetName",
              "Value": "Others"
            },
            {
              "Key": "CallCategory",
              "Value": "Installation"
            }
          ]

How to manage this. Pls find the below code.

$http.post("http://crm.test.com/GetAllObjects",
                                {"objectId":null,"objects":null,"searchParams":null,"sessionId":"DB06442E-2993-4FE8-B496-5A0CF61C8342","type":8})
                     .success(function(data) {
                              alert("SUCCESS!");
                              console.log(data);
                              })
                     .error(function(data) {
                            alert("ERROR");
                            alert(data);
                            });

You need to implement nested ng-repeat for this purpose as

              ng-repeat = "obj in list.objects"

                     ng-repeat = "obj1 in obj,Fields 

Populate these ng-repeat as per your requirement

Can you please explain me bit more as per my json structure.

myhtml.html

<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="item in callItems" type="item-text-wrap" ng-click="doTask()">

                        <h3 style="color:black;">{{item.CallID}}</h3>
                        <h3 style="color:black;">{{item.CallDate}}</h3>
                        <p style="color:black;">{{item.ClientName}}</p>
                        <p style="color:black;">{{item.AssetName}}</p>
                        <p style="color:black;">{{item.CallCategory}}</p>

            </ion-item>

myjs.js

$http.post("http://testCrm.com/GetAllObjects",
                       {"objectId":null,"objects":null,"searchParams":null,"sessionId":"DB06442E-2993-4FE8-B496-5A0CF61C8342","type":8})
            .success(function(data) {
                     alert("SUCCESS!");
                     
                     $rootScope.callItems = data;
                     console.log($rootScope.callItems);
                     
                     })
            .error(function(data) {
                   alert("ERROR");
                   alert(data);
                   });

myresponse.json:

$rootScope.callItems is below one.

{“employeeId”:"",“id”:“C60CE485-EA0F-4554-BAEA-FB07CB13710A”,“message”:“Username / Password incorrect”,“objects”:null,“success”:false}
2016-09-12 16:05:32.893 RevolApp[6983:2289610] {“employeeId”:null,“id”:“DB06442E-2993-4FE8-B496-5A0CF61C8342”,“message”:null,“objects”:[{“Children”:[],“Fields”:[{“Key”:“CallID”,“Value”:“1000”},{“Key”:“CallDate”,“Value”:“Sep 9 2016 10:14AM”},{“Key”:“ClientName”,“Value”:""},{“Key”:“AssetName”,“Value”:“Automatic Cold Cranking Simulator”},{“Key”:“CallCategory”,“Value”:“Corrective Maintenance”}],“Type”:8},{“Children”:[],“Fields”:[{“Key”:“CallID”,“Value”:“1000”},{“Key”:“CallDate”,“Value”:“Sep 9 2016 10:20AM”},{“Key”:“ClientName”,“Value”:""},{“Key”:“AssetName”,“Value”:“Auto Mini Pour Point Tester “},{“Key”:“CallCategory”,“Value”:“Preventive Maintenance”}],“Type”:8},{“Children”:[],“Fields”:[{“Key”:“CallID”,“Value”:“1000”},{“Key”:“CallDate”,“Value”:“Sep 9 2016 10:23AM”},{“Key”:“ClientName”,“Value”:””},{“Key”:“AssetName”,“Value”:“Balance - Citizon CX 220”},{“Key”:“CallCategory”,“Value”:“Calibration”}],“Type”:8},{“Children”:[],“Fields”:[{“Key”:“CallID”,“Value”:“1001”},{“Key”:“CallDate”,“Value”:“Sep 9 2016 10:26AM”},{“Key”:“ClientName”,“Value”:""},{“Key”:“AssetName”,“Value”:“Others”},{“Key”:“CallCategory”,“Value”:“Installation”}],“Type”:8}],“success”:true}

Can you please help in this.

Pls find this answer :slight_smile: