zoukankan      html  css  js  c++  java
  • json转字符串 —— jsonObj.toJSONString()与JSON.stringify(jsonObj)json to string

     json 转变成 string方法介绍:

    var people = { "programmers": [{ "firstName": "Brett", "lastName": "McLaughlin", "email": "aaaa" }, { "firstName": "Jason", "lastName": "Hunter", "email": "bbbb" }, { "firstName": "Elliotte", "lastName": "Harold", "email": "cccc"}],
        "authors": [{ "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" }, { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" }, { "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction"}],
        "musicians": [{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" }, { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano"}]
    };
    alert(JSON.stringify(people));

    上面的, 只能在IE8或者以上, Firefox下运行

    方法toJSONString() , 必须要引入https://github.com/douglascrockford/JSON-js/blob/master/json.js

    局限性都比较大

  • 相关阅读:
    作业07-Java GUI编程
    作业06-接口、内部类
    作业05-继承、多态、抽象类与接口
    作业14-数据库
    作业13-网络
    作业12-流与文件
    作业11-多线程
    作业10-异常
    作业09-集合与泛型
    作业08-集合
  • 原文地址:https://www.cnblogs.com/wolfocme110/p/4000469.html
Copyright © 2011-2022 走看看