JSON.parse and JSON.stringify

This question already has an answer here:

  • How can I pretty-print JSON using JavaScript? 20 answers

  • 你需要一个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/8450.html

    上一篇: 我如何打印JavaScript对象/变量?

    下一篇: JSON.parse和JSON.stringify