#What is json?
JSON (JavaScript Object Notation) is a lightweight data exchange format that is easy to read and write, as well as easy for machines to parse and generate. .
The structure of JSON is based on the following two points
1. A collection of "name/value" pairs. In different languages, it is understood as an object (object), a record (record), a structure (struct) ), dictionary, hash table, keyed list, etc.
2. An ordered list of values is understood as an array in most languages
JSON usage:
JSON represents JavaScript objects in a specific string form. If you assign a string with such a form to any JavaScript variable, then the variable will become an object reference, and this object is constructed from the string. It seems a bit confusing, so we will use an example to illustrate.
Assume here that we need to create a User object with the following attributes
User ID
User Name
User Email
You You can use the following JSON form to represent the User object:
{"UserID":11, "Name":"Truly", "Email":"zhuleipro◎hotmail.com"};
Then if you assign this string to a JavaScript variable, you can directly use any property of the object.
Full code:
<script> var User = {"UserID":11, "Name":"Truly", "Email":"zhuleipro◎hotmail.com"}; alert(User.Name); </script>
The above is the detailed content of what is json. For more information, please follow other related articles on the PHP Chinese website!