Craftstrail
Craftstrail

Reputation: 77

How to Parse Json In angular Js

Hi I am trying to parse json in angular js but didn't get answer pease help me

<div ng-app="" ng-controller="customersController"> 

<table>
  <tr ng-repeat="x in names">
    <td>{{ x.id }}</td>
    <td>{{ x.mkrDate }}</td>
  </tr>
</table>


</div>

<script>
function customersController($scope,$http) {
  $http.get("http://www.w3schools.com/website/Customers_MySQL.php")
  .success(function(response) {$scope.names = response;});
}
</script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>

O/P:-

{
   "id":"09851021211557572",
   "mkrDate":1392023642000,
   "mkrId":null,
   "mkrName":null,
   "timestamp":1410172522974,
   "editorId":null,
   "editorName":null,
   "firstName":"Nandan",
   "lastName":"Umarji",
   "gender":null,
   "dob":null,
   "emailAdd":"[email protected]",
   "mobileNo":"9819693822",
   "userName":"[email protected]",
   "password":"252117652",
   "confirmationCode":"vkt95bf5c",
   "photoUrl":null,
   "accountType":"Company",
   "bussinessName":"Mactores",
   "companyUrl":"http://www.mactores.com",
   "websiteUrls":"http://www.mactores.com    ",
   "countryCode":"+91",
   "forgetPasswordCodeExpired":false,
   "forgetPasswordCode":"vkt558e1e",
   "address":{
      "building":null,
      "street":"Mumbai",
      "area":null,
      "location":null,
      "landmark":null,
      "city":"Mumbai",
      "state":"Maharashtra",
      "country":"India",
      "pincode":"400001"
   },
   "request":true,
   "confirm":false,
   "deleted":false
}

Upvotes: 0

Views: 615

Answers (2)

Rusty
Rusty

Reputation: 329

It will work if you change the code to:

<table>
    <tr>
        <td>{{ names.id }}</td>
        <td>{{ names.mkrDate }}</td>
    </tr>
</table>

Or you can add brackets ( [ ] ) to the beginning and end of the json.

Upvotes: 1

bmazurek
bmazurek

Reputation: 169

try to use <pre>{{ {'name':'value'} | json }}</pre>

https://docs.angularjs.org/api/ng/filter/json

Upvotes: 1

Related Questions