Where/when we use JSON?

2020-05-19 15:40发布

Could you please tell me, what is the use of JSON (in Javascript and PHP). when we need a JSON method.

I read from the following link but, i didn't get any information regarding the JSON implementation on any project.

http://www.json.org/js.html

9条回答
够拽才男人
2楼-- · 2020-05-19 16:18

JSON is mostly used as a lightweight and more human readable alternative to XML in AJAX web apps.

查看更多
beautiful°
3楼-- · 2020-05-19 16:21

All of the other answers are great, but perhaps the simplest explanation for your specific case (JavaScript + PHP): JSON is the easiest way to translate a JavaScript object into a PHP associative array or object (and vice-versa).

Take a look at json_encode() and json_decode() for the PHP side of things. On the JavaScript side, a simple eval() is the easiest (but least-safe!) way to get an object out of a JSON string, but your library of choice will certainly have functions to take care of this for you, and if you're targeting newer browsers you can use the ECMAScript 5 JSON object.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2020-05-19 16:22

Despite its name, one of the primary uses of the JSON format is in AJAX web development (though certainly not the only one). It is often preferred over the traditional XML for its light-weight syntax.

查看更多
登录 后发表回答