本文介绍了getJSON到console.log()以输出json结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码用于获取json数据:

I have the following code for getting json data:

$.getJSON( "assessments", function( assessments ) {
    console.log(assessments);
        });

我可以很好地获取所有数据,但控制台的输出为

I am perfectly getting all the data but the console has output as

[Object, Object, Object, Object, Object, Object, Object, Object, Object]

我想像这样在JSON结构中输出值:

I want to output the values in JSON structure like this:

[
{
    "id": 1,
    "person": {
        "personId": "person1",
        "firstName": "Pactric"
    },
    "manager": {
        "managerId": "manager1"
    },
    "state": {
        "stateId": 1,
        "description": null
    },
    "comments": null
}
]

如何使用console.log()将此数据完全显示为上述JSON结构?我正在为此应用程序使用$ .getJSON而不是$ .ajax.

How to console.log() for this data to display exactly as above's JSON structure?I am using $.getJSON NOT $.ajax for this application.

推荐答案

尝试

console.log(JSON.stringify(assessments));

这篇关于getJSON到console.log()以输出json结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:49