如何使用console.log打印JSON

Art*_*rty 6 ajax typescript reactjs

我正在用php laravel和编写一个程序react.js.但我对这些很新.无论如何react,我正在发送API请求ajax.

像这样:

const sendquery = {
    "async": true,
    "crossDomain": true,
    "url": url,
    "method": "POST",
    "headers": {
        "Authorization": "Bearer " + tkid,
        "Accept": "application/json",
        "Content-Type": "application/json",
    },
    "processData": false,
    "data": query
};

$.ajax(sendquery).done(function (response) {
    console.log('Survey Request :' + response);
});
Run Code Online (Sandbox Code Playgroud)

还有另一个API请求在我打印时很好,console.log()因为它们是数组类型.但这一定是json.我用Postman测试了API 一切正常.但我仍然有这样的输出:

Survey Request :[object Object]
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

Bar*_*ray 5

您可以尝试使用,JSON.stringify(response)但请注意,它不适用于所有类型,例如,请参阅JSON.stringify不适用于普通Javascript数组