Angular js Parsing Json object

前端 未结 2 1120
清歌不尽
清歌不尽 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:15

    To parse "lastlogin": "{\"employees\":[{\"firstName\":\"John\"}, {\"firstName\":\"Blake\"}]}" data correctly you can use

    angular.fromJson(User.lastLogin);
    

    Just make sure that you are giving inner object i.e. lastlogin to the method and it will remove all invalid characters such as \ and " from the json data.

提交回复
热议问题