zoukankan      html  css  js  c++  java
  • angular内置方法---序列化、反序列化

    toJson:将对象或者数组 序列化 为json格式的字符串

    fromJson:相反的过程

     1 <!DOCTYPE html>
     2 <html ng-app="myApp">
     3 <head lang="en">
     4   <meta charset="UTF-8">
     5   <title></title>
     6   <script src="js/angular.js"></script>
     7 </head>
     8 <body>
     9 
    10 <div ng-controller="myCtrl">
    11 
    12 </div>
    13 
    14 <script>
    15   var app = angular.module('myApp', ['ng']);
    16 
    17   app.controller('myCtrl', function ($scope) {
    18 
    19   //反序列化
    20     var jsonStr = '{"name":"zhangsan","age":20}';
    21     var result = angular.fromJson(jsonStr);
    22     console.log(result); console.log(resultStr);
    23                 //Object                                age: 20name: "zhangsan"__proto__: Object
    24 
    25 
    26   //序列化:将对象或者数组 序列化 为json格式的字符串 方便和服务器端的交互
    27     var resultStr = angular.toJson(result);
    28               // {"name":"zhangsan","age":20}
    29 
    30 //    angular.lowercase/uppercase()
    31 
    32 //    遍历
    33     var list = [100,200,300];
    34     angular.forEach(list, function (value,key) {
    35       console.log(key,value);
    36     })
    37 
    38   });
    39 </script>
    40 </body>
    41 </html>
  • 相关阅读:
    理解java的三大特性之封装
    特征学习
    Java类编译、加载、和执行
    榜样
    组合学习模型
    python的re模块详解
    python的argpare和click模块详解
    vue的组件
    vue的表单输入绑定
    vue的事件处理梳理
  • 原文地址:https://www.cnblogs.com/i-want-to-be-like-an-sun/p/7644363.html
Copyright © 2011-2022 走看看