zoukankan      html  css  js  c++  java
  • toJSON 方法 (Date) (JavaScript)

    toJSON 方法 (Date) (JavaScript)  


    语法:objectname.toJSON()  
    objectname  
    必需。 需要进行 JSON 序列化的对象。  
    toJSON 方法是 Date JavaScript 对象的内置成员。 它返回 UTC 时区的 ISO 格式日期字符串(由后缀 Z 表示)。  


    以下示例使用 toJSON 方法将大写的字符串成员值序列化。 在调用 JSON.stringify 时调用 toJSON 方法。  

    var contact = new Object(); contact.firstname = "Jesper"; contact.surname = "Aaberg"; 
    contact.phone = ["555-0100", "555-0120"];  
    contact.toJSON = function(key)  { 
        var replacement = new Object();     
    
        for (var val in this){ 
            if (typeof (this[val]) === 'string') 
                replacement[val] = this[val].toUpperCase();        
    
            else 
                replacement[val] = this[val]     
    
        } 
        return replacement;
    
     };  
    var jsonText = JSON.stringify(contact);  
    
    
    /* The value of jsonText is: 
    '{"firstname":"JESPER","surname":"AABERG","phone":["555-0100","555-0120"]}' */
  • 相关阅读:
    网络协议 22
    网络协议 21
    网络协议 20
    网络协议 19
    网络协议 18
    网络协议 17
    网络协议 16
    网络协议 15
    网络协议 14
    .net 4.0 中的特性总结(五):并行编程
  • 原文地址:https://www.cnblogs.com/givemeanorange/p/4611000.html
Copyright © 2011-2022 走看看