How to create JSON string in JavaScript?

前端 未结 7 1791
借酒劲吻你
借酒劲吻你 2020-12-23 02:31
window.onload = function(){
    var obj = \'{
            \"name\" : \"Raj\",
            \"age\"  : 32,
            \"married\" : false
            }\';

    var va         


        
相关标签:
7条回答
  • 2020-12-23 03:29

    The function JSON.stringify will turn your json object into a string:

    var jsonAsString = JSON.stringify(obj);
    

    In case the browser does not implement it (IE6/IE7), use the JSON2.js script. It's safe as it uses the native implementation if it exists.

    0 讨论(0)
提交回复
热议问题