0

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
}

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.