Home >Web Front-end >JS Tutorial >Are there any built-in methods in angularjs?
toJson: Serialize an object or array into a string in json format
fromJson: The reverse process
<!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta charset="UTF-8"> <title></title> <script src="js/angular.js"></script></head><body><p ng-controller="myCtrl"></p><script> var app = angular.module('myApp', ['ng']); app.controller('myCtrl', function ($scope) { //反序列化 var jsonStr = '{"name":"zhangsan","age":20}'; var result = angular.fromJson(jsonStr); console.log(result); console.log(resultStr); //Object age: 20name: "zhangsan"__proto__: Object //序列化:将对象或者数组 序列化 为json格式的字符串 方便和服务器端的交互 var resultStr = angular.toJson(result); // {"name":"zhangsan","age":20}// angular.lowercase/uppercase()// 遍历 var list = [100,200,300]; angular.forEach(list, function (value,key) { console.log(key,value); }) });</script></body></html>
The above is the detailed content of Are there any built-in methods in angularjs?. For more information, please follow other related articles on the PHP Chinese website!