Shiv Suthan M Shiv Suthan M - 2 months ago 9
JSON Question

How to query critical JSON into ionic

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
}


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);
});


As per my code I can able to get the response But How can i parse the value in View ?

Answer

this might not be the best solution but it's a working demo. i think you need to change the json object structure again and re create it according to your requirement.

 <div ng-repeat="item in callItems.objects">
      <div ng-repeat="fi in item" >
        <div ng-repeat="kk in fi">
          <h3 style="color:black;" ng-if="kk.Key == 'CallID'">{{kk.Value}}</h3>
          <h3 style="color:black;" ng-if="kk.Key == 'CallDate'">{{kk.Value}}</h3>
          <h3 style="color:black;" ng-if="kk.Key == 'ClientName'">{{kk.Value}}</h3>
          <h3 style="color:black;" ng-if="kk.Key == 'AssetName'">{{kk.Value}}</h3>
          <h3 style="color:black;" ng-if="kk.Key == 'CallCategory'">{{kk.Value}}</h3>
        </div> 
      </div>