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 struct 中的值,如下所示:

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

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

推荐答案

try with

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

Json相关问答推荐

JOLT将扁平数组内其他字段的两个值相乘

时间和日期数据绘制不正确

使用相同的密钥值来命名Json并使用Jolt重命名密钥

Vega-Lite:文本笔画在外部

最新版本的Deneb在数据溢出时不支持滚动

有没有办法让serde_json正确/不正确地处理NaN、inf和-inf(IEEE 754特殊标准)?

在深度嵌套数组中使用布尔属性的jq-select

在Databricks中如何将JSON文件作为字典读取

Groovy JsonBuilder 在for循环中添加数组元素

具有 (RegEx) 模式的 json-schema 中的枚举

jq - 仅在键值对存在的地方打印值

如何将 JSON 文本作为参数传递给 powershell?

shell解析json并循环输出组合变量

如何使用 boost::json::value 调用无参数函数

自定义将 struct 解组为切片映射

Powershell JSON 操作

如何判断字符串是否为json格式

我应该如何处理 JSON 中的 HATEOAS 链接和引用?

JSON Schema:验证数字或空值

Spring restTemplate 获取原始 json 字符串