JSON.parse和JSON.stringify

这个问题在这里已经有了答案:

  • 我怎样才能使用JavaScript漂亮地打印JSON? 20个答案

  • 你需要一个PRE标签来保持好的缩进(或者在你的目标标签中添加CSS white-space:pre ),然后使用JSON.stringify的第三个参数来添加缩进

    var data = '[{"match_id":3469695808,"player_slot":3,"radiant_win":true,"duration":1237,"game_mode":22,"lobby_type":7,"hero_id":13,"start_time":1506540251,"version":20,"kills":11,"deaths":2,"assists":12,"skill":3,"leaver_status":0,"party_size":1}]'
    
    document.getElementById('demo').innerHTML = JSON.stringify(JSON.parse(data),null, 4);
    <pre id="demo"></pre>
    链接地址: http://www.djcxy.com/p/8449.html

    上一篇: JSON.parse and JSON.stringify

    下一篇: How to place text of a div as a json string?