我一直对何时使用这两种解析方法感到困惑。
在我回显json_encoded数据并通过ajax检索它之后,我经常对何时应该使用JSON感到困惑。stringify和JSON.parse。
我得到[对象,对象]在我的控制台.log解析和JavaScript对象时stringized。
$.ajax({
url: "demo_test.txt",
success: function(data) {
console.log(JSON.stringify(data))
/* OR */
console.log(JSON.parse(data))
//this is what I am unsure about?
}
});