angular.fromJson与toJson方法用法示例
本文实例讲述了angular.fromJson与toJson方法用法。分享给大家供大家参考,具体如下:
AngularJS的angular.fromJson()方法可以把一个Json字符串中解析成一个对象,或对象数组:
angular.module("App",[]) .controller("parseController",function($scope) { $scope.parse=function() { varjson='{"name":"liSi","password":"321"}'; varjsonArr='[{"name":"zhangSan","password":"123"},{"name":"liSi","password":"321"}]'; varobj=angular.fromJson(json); console.log(obj.name); varobjArr=angular.fromJson(jsonArr); console.log(objArr[0].name); console.log(objArr[1].password); } }); 点击我!