为什么在通过AJAX发送数据时,您是否需要JSON.stringify()您的对象? [英] Why when sending data over AJAX, do you have to JSON.stringify() your objects?

查看:405
本文介绍了为什么在通过AJAX发送数据时,您是否需要JSON.stringify()您的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSON代表javascript对象表示法(因为我确定你知道),所以为什么,当通过ajax发送json时你需要把它变成一个字符串来发送它吗?它只是一个格式化的东西,或者是什么?

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?

这可能属于另一个地方,如果是这样,请告诉我,我会关闭它并移动它。

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.

为了确保我清楚,我理解JSON.stringify()做了什么,以及它的对应JSON.parse()。我只是想知道,为什么需要使用stringify。

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.

谢谢!

推荐答案


当通过ajax发送json时你需要把它变成一个字符串来发送吗?

when sending json via ajax do you need to turn it into a string to send it?

如果它不是字符串,那么它首先不是JSON。

If it isn't a string, then it isn't JSON in the first place.

JSON是基于文本的数据格式。 HTTP是基于文本的通信协议。

JSON is a text based data format. HTTP is a text based communications protocol.


JSON代表javascript对象表示法

JSON stands for javascript object notation

JSON基于JavaScript文字的语法。 JavaScript对象不是JSON。

JSON is based on the syntax for JavaScript literals. A JavaScript object is not JSON.

这篇关于为什么在通过AJAX发送数据时,您是否需要JSON.stringify()您的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆