简体   繁体   中英

How do I format single array nested JSON data and print it a browser using AJAX

I need help in formatting single array nested JSON data and displaying it in a browser. My main issue is picking a single id of an array of data, formatting it, and printing it on a browser.

I have so far succefully print only array using $('#data').html( JSON.stringify(response)); , but no idea on how to print or display formatted JSON on a browser.

<div id="data"></div>

<script>
let response = [
    {"person":[{"id":1,"Name":"ben","Location":"uk","History":"Born 1990","Status":"male"}]}
];


$('#data').html( JSON.stringify(response));

</script>

Kindly

can't get your question properly, Are You asking about how to display the data inside the array using an specific id?

if it is the question, then try the below code,

$('#data').html(JSON.stringify(response[0].person[0]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM