Angular js Parsing Json object

前端 未结 2 1102
清歌不尽
清歌不尽 2021-01-04 08:58

A json object has a key lastLogin. Value of it is a string.

I am trying to print firstName John and Blake

$scope._u         


        
2条回答
  •  醉梦人生
    2021-01-04 09:26

    Try like this

    View

    {{emp.firstName}}

    Controller

    var myApp = angular.module('myApp', []);
    
    function MyCtrl($scope) {
        $scope.getName = function (user) {
            return "Names";
        };
    
        $scope._users = [{
            "User": {
                "userid": "dummy",
                    "lastlogin": "{\"employees\":[{\"firstName\":\"John\"},                   {\"firstName\":\"Blake\"}]}",
            }
        }];
        $scope.parJson = function (json) {
            return JSON.parse(json);
        }
        //console.log(JSON.parse($scope._users[0].User.lastlogin));
    }
    

    DEMO

    you can also use angular.fromJson.

    Like this

    $scope.parJson = function (json) {
       return angular.fromJson(json);
    }
    

    DEMO

提交回复
热议问题