json转字符串 —— jsonObj.toJSONString()与JSON.stringify(jsonObj)

Posted Fight With Me!!!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json转字符串 —— jsonObj.toJSONString()与JSON.stringify(jsonObj)相关的知识,希望对你有一定的参考价值。

ar 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

 

局限性都比较大

以上是关于json转字符串 —— jsonObj.toJSONString()与JSON.stringify(jsonObj)的主要内容,如果未能解决你的问题,请参考以下文章

jslist转json字符串然后转小写

JS json字符串转对象对象转字符串

前端js把json字符串转json对象 java对象转json对象命令

JSON--js中 json字符串转对象对象转字符串

java中字符串怎么转json?

php如何将json对象转字符串