JSON stands for javascript object notation (as I'm sure you're aware), so why, when sending json via ajax do you need to turn it into a string to send it? Is it simply a formatting thing, or what?
JSON代表javascript对象表示法(因为我确定你知道),所以为什么,当通过ajax发送json时你需要把它变成一个字符串来发送它吗?它只是一个格式化的东西,或者是什么?
This may belong in another place, if so, let me know, I'll close it and move it.
这可能属于另一个地方,如果是这样,请告诉我,我会关闭它并移动它。
Obviously, I'm not looking for opinions, I'd like to know the actual answer.
显然,我不是在寻找意见,我想知道实际的答案。
Just to make sure I'm clear, I understand what JSON.stringify() does, and its counterpart JSON.parse(). I just want to know, why using stringify is required.
为了确保我清楚,我理解JSON.stringify()做了什么,以及它的对应JSON.parse()。我只是想知道,为什么需要使用stringify。
Thanks!
谢谢!
2 个解决方案
#1
11
when sending json via ajax do you need to turn it into a string to send it?
通过ajax发送json时你需要把它变成一个字符串来发送吗?
If it isn't a string, then it isn't JSON in the first place.
如果它不是字符串,那么它首先不是JSON。
JSON is a text based data format. HTTP is a text based communications protocol.
JSON是基于文本的数据格式。 HTTP是基于文本的通信协议。
JSON stands for javascript object notation
JSON代表javascript对象表示法
JSON is based on the syntax for JavaScript literals. A JavaScript object is not JSON.
JSON基于JavaScript文字的语法。 JavaScript对象不是JSON。
#2
1
AJAX is all about HTTP requests, which are basically "text" requests to a server. That's the main reason why you have to stringify your object: That way it's turned into text that can "travel" over HTTP.
AJAX是关于HTTP请求的全部内容,它基本上是对服务器的“文本”请求。这就是你必须对你的对象进行字符串化的主要原因:这样它就变成了可以通过HTTP“旅行”的文本。
#1
11
when sending json via ajax do you need to turn it into a string to send it?
通过ajax发送json时你需要把它变成一个字符串来发送吗?
If it isn't a string, then it isn't JSON in the first place.
如果它不是字符串,那么它首先不是JSON。
JSON is a text based data format. HTTP is a text based communications protocol.
JSON是基于文本的数据格式。 HTTP是基于文本的通信协议。
JSON stands for javascript object notation
JSON代表javascript对象表示法
JSON is based on the syntax for JavaScript literals. A JavaScript object is not JSON.
JSON基于JavaScript文字的语法。 JavaScript对象不是JSON。
#2
1
AJAX is all about HTTP requests, which are basically "text" requests to a server. That's the main reason why you have to stringify your object: That way it's turned into text that can "travel" over HTTP.
AJAX是关于HTTP请求的全部内容,它基本上是对服务器的“文本”请求。这就是你必须对你的对象进行字符串化的主要原因:这样它就变成了可以通过HTTP“旅行”的文本。