jquery display formatted json

前端 未结 1 557
情书的邮戳
情书的邮戳 2021-02-13 04:59

Hi i have a problem becouse my json isn\'t display as formatted json.

in my web page i have a

 tag, it cointains json string:

相关标签:
1条回答
  • 2021-02-13 05:37

    JSON.stringify takes an object, but you are passing it a string. To use this approach, you would need to turn your string into an object then back into a string:

    http://jsfiddle.net/yEez8/

    var jsonStr = $("pre").text();
    var jsonObj = JSON.parse(jsonStr);
    var jsonPretty = JSON.stringify(jsonObj, null, '\t');
    
    $("pre").text(jsonPretty);
    
    0 讨论(0)
提交回复
热议问题