getJSON to console.log() to output json structure

前端 未结 2 693
北恋
北恋 2020-12-24 11:06

I have the following code for getting json data:

$.getJSON( \"assessments\", function( assessments ) {
    console.log(assessments);
        });
2条回答
  •  执念已碎
    2020-12-24 11:39

    Stringify the JSON with indentation like so :

    $.getJSON( "assessments", function( assessments ) {
        console.log(JSON.stringify(assessments, undefined, 2))
    });
    

    JSON.stringify(value[, replacer [, space]]) where space is the indent. MDN

提交回复
热议问题