Recursively parsing JSON

后端 未结 4 1440
情歌与酒
情歌与酒 2021-01-03 07:51

I have a large JSON object that I created with Python, and I\'m needing to display the information on a webpage now. My problem is the size of it; there are nested arrays an

4条回答
  •  耶瑟儿~
    2021-01-03 08:26

    You could use a JS templating engine to transform your JSON to a humanly readable HTML.

    Here is an example of recursion with the PURE templating lib: http://beebole.com/pure/documentation/recursion-example/

    The template here is quite generic, using a UL/LI combination.

    Or if you want to render it for instance in a textbox you can use JSON.stringify:

    document.getElementById('theTextBox').value = JSON.stringify(theJson, null, 2);
    

    The call above to stringify will indent the JSON with 2 spaces.

提交回复
热议问题