简体   繁体   English

如何格式化单个数组嵌套的 JSON 数据并使用 AJAX 将其打印到浏览器

[英]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.我需要帮助格式化单个数组嵌套 JSON 数据并将其显示在浏览器中。 My main issue is picking a single id of an array of data, formatting it, and printing it on a browser.我的主要问题是选择一组数据的单个 id,对其进行格式化,然后将其打印在浏览器上。

I have so far succefully print only array using $('#data').html( JSON.stringify(response));到目前为止,我仅使用$('#data').html( JSON.stringify(response));成功打印了数组$('#data').html( JSON.stringify(response)); , but no idea on how to print or display formatted JSON on a browser. ,但不知道如何在浏览器上打印或显示格式化的 JSON。

<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?无法正确回答您的问题,您是在询问如何使用特定 id 显示数组内的数据吗?

if it is the question, then try the below code,如果是问题,请尝试以下代码,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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