<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>angular.formJson</title> </head> <body ng-app="forJsonExample"> <h1>angular.formJson</h1> <p> <span>描述:</span><br /> <span>把json字符串转回为对象</span> </p> <p> <span>使用方法:</span><br /> <span>angular.formJson(json)</span> </p> <p> <span>参数:</span><br /> <span>json: String,json字符串</span><br /> </p> <p> <span>返回值:</span><br /> <span>对象, 数组, 字符串 或者是一个数字</span> </p> <hr /> <div ng-controller="forJsoncon"> <span>把json字符串转回为对象: {{a}}</span> </div> </body> <script src="../../js/angular.1.3.0.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> angular.module('forJsonExample', []).controller('forJsoncon', ['$scope', function($scope) { var json = '{"name":"liSi", "password":"321"}'; var jsonArr = '[{"name":"zhangSan", "password":"123"},{"name":"liSi", "password":"321"}]'; var obj = angular.fromJson(json); $scope.a = obj; console.log(json); var objArr = angular.fromJson(jsonArr); console.log(objArr[0].name); console.log(objArr[1].password); }]) </script> </html>