angular.fromJson

angular.fromJson
描述:
把Json字符串转为对象
使用方法:
angular.fromJson(json);
参数详解:
Param Type Details
json string

JSON 字符串

返回值:
对象, 数组, 字符串 或者是一个数字
示例:
<!DOCTYPE HTML>
<html ng-app="exampleApp">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script src="angular.min.js"></script>
	<script>
	var exampleApp = angular.module('exampleApp',[]);
	
	exampleApp.controller('ShowController',['$scope', function($scope){
		
		
		$scope.fromJson = function() {
			var strUser = "{\"firstName\":\"fox\",\"lastName\":\"zhang\"}";
			
			var objUser = angular.fromJson(strUser);
			alert(objUser.firstName);
		}
		
	}]);
	

	</script>
</head>

<body>
<div id="test">博弈网络科技</div>

	<div>
		<div>
		angular.fromJson("{\"firstName\":\"fox\",\"lastName\":\"zhang\"}")
		</div>
		
		<div id="myCtrl" ng-controller="ShowController">

      <input type="button" id="btnToJson" ng-click="fromJson()" value="objUser.firstName" />
		 </div> 
		
	</div>
<hr>



</body>	
</html>
 

你可能感兴趣的:(AngularJS,AngularJS 官方API,AngularJS API)