What is JSON used for in web applications?
I am relatively new to web development and web applications. I have heard about JSON but am not sure exactly what its uses are.
JSON is a format for encoding information returned by the server. When you call a script with AJAX/XHR (eg with JavaScript) the returned information can come via XML, JSON, or another format. JSON is simply a way to return that data in an object structure native to JavaScript - in a way that generally doesn't require a lot of parsing, like XML does.
It is a kind of language for encoding information. For example, if you want to send information about person from one place to another, then it JSON it may look like this:
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address":
{
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021"
},
"phoneNumber":
[
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
Taken from wiki. :) See http://en.wikipedia.org/wiki/JSON for more details.
First, it's an acronym for JavaScript Object Notation.
It is often used in places where applications deal with object data structures (often seen in languages such as Java, C#, etc.), and associative arrays (key-value pairs seen in many languages such as Python, PHP, etc.)
To answer your question, it's a simple and efficient way to encode objects into strings, transfer them, and recreate the objects on the other end.
JSON on Wikipedia
JSON Homepage
Example of JSON encoding in PHP
链接地址: http://www.djcxy.com/p/47828.html上一篇: 存储包含MYSQL数据库中的对象的JavaScript数组?
下一篇: 什么是在Web应用程序中使用JSON?