2

I am just unable to access values from the my json string (image below).

{
    all: [{
        info: {
            name: "Fahad",
            lat: "41.954815",
            lon: "-87.647209"
        }
    }, {
        info: {
            name: "Fahad",
            lat: "41.954815",
            lon: "-87.647209"
        }
    }, {
        info: {
            name: "Fahad",
            lat: "41.954815",
            lon: "-87.647209"
        }
    }],
    rowsfound: "11"
}

I am using angularjs, here is html

<ul ng-controller="PostsCtrl">
    <li ng-repeat="post in posts">
        {{post.all[0].info.name}}  <em>{{post.rowsfound}}</em>
    </li>
</ul>

Controller:

app.controller("PostsCtrl", function ($scope, $http) {
    $http.get(myurl)
        .success(function (data) {
        $scope.posts = data;

    }).error(function (data, status, headers, config) {
        alert("error");
    });
});

two list items generated without any value. whats the wrong thing am I doing?

Thanks

3
  • 5
    Can you console.log data and paste the exact result here? Commented Sep 3, 2014 at 12:50
  • As suggested by Mathew, your data might be wrapped in another object. You should console.log it and see what it looks like. Could be something like data.results to access your posts. Commented Sep 3, 2014 at 12:51
  • Answer below done that. Checked console.log, but original data is pvt. so can't paste here. Commented Sep 3, 2014 at 13:11

2 Answers 2

3

use this html:

<ul ng-controller="PostsCtrl">
    <li ng-repeat="post in posts.all">
        {{post.info.name}}  <em>{{posts.rowsfound}}</em>
    </li>
</ul>
Sign up to request clarification or add additional context in comments.

Comments

0

Your JSON representation is wrong, correct is "name": "Fahad" etc. You can use tools like http://jsonlint.com/ to check if your JSON is valid.

1 Comment

I know, but the problem is that the a lot of services returning like the same, so I can't go and correct at the moment but to use as is.

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.