I have been confused over when to use these two parsing methods.
(我一直很困惑何时使用这两种解析方法。)
After I echo my json_encoded data and retrieve it back via ajax, I often run into confusion about when I should use JSON.stringify and JSON.parse .
(在我回显我的json_encoded数据并通过ajax将其检索回来之后,我经常会对何时应该使用JSON.stringify和JSON.parse感到困惑。)
I get [object,object]
in my console.log when parsed and a JavaScript object when stringified.
(我在解析时在我的console.log中获取[object,object]
,在字符串化时获得JavaScript对象。)
$.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?
}
});
ask by HIRA THAKUR translate from so