JSON can also be a JSON array, for example, in JSON, where a task information is encapsulated, and several attachments are defined in this task as follows:
Jsonarray Taskjsonarray = Newjsonarray ();
Jsonobject taskjsonobj = Newjsonobject ();
Taskjsonobj.put ("TaskId");
Taskjsonobj.put ("TaskName", "MyTask");
Taskjsonobj.put ("Attchs", Jsonarray);
Taskjso
in JSON can also be a JSON array, for example, in JSON, where a task information is encapsulated, and several attachments are defined in this task as follows:
Jsonarray Taskjsonarray = Newjsonarray (); Jsonobject taskjsonobj = Newjsonobject (); Taskjsonobj.put ("TaskId")
; Taskjsonobj.put ("TaskName", "MyTask"); Taskjsonobj.put ("Attchs", Jsonarray); Ta
} ';$obj = Json_decode ($json);Print $obj->{' foo '}; 12345
Typically, Json_decode () always returns a PHP object instead of an array. Like what:
Copy the Code code as follows:$json = ' {' A ': 1, ' B ': 2, ' C ': 3, ' d ': 4, ' E ': 5} ';Var_dump (Json_decode ($json));
The result is to generate a PHP object:
Copy the
The above describes how to represent data in JSON, and then we will also work out how to generate JSON-formatted data on the server side for sending to the client, and how the client uses JavaScript to process data in JSON format.Let's start by looking at how the server outputs JSO
JSON (JavaScript Object notation) is a lightweight data interchange format. Easy for people to read and write. It is also easy to machine parse and generate. It is based on JavaScript programming Language, Standard ECMA-262 a subset of 3rd Edition-december 1999. JSON uses a completely language-independent text format, but it also uses a family of C-language (c, C
Php returns the json data function example, and php returns the json function. Php returns the json data function example. php returns the json function json_encode. Echojson_encode (array (abbbb, cddddd); this will generate a standard j
1. Introduction to JSON
JSON (JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family (including C, C ++, C #, Java, JavaS
JSON(JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. It is based on a subset of JavaScript programming language, standard ECMA-262 3rd edition-December 1999. JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family (
a PHP object instead of an array. Like what:
$json = ' {' A ': 1, ' B ': 2, ' C ': 3, ' d ': 4, ' E ': 5} '; Var_dump (Json_decode ($json));
The result is to generate a PHP object:
Object (StdClass) #1 (5) {["a"] + int (1) ["b"] = + int (2) ["c"] = = Int (3) ["D"] = + int (4) ["E" ] = = Int (5)}
If you want to force a PHP associative array to be generated, jso
1. Introduction to JSONJSON (JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family (including C, C ++, C #, Java, JavaScript, Perl, Python, and so on ). These features make
Parses an instance in json format data 2 and a json instanceParsing instances in json format data 2
Json is a commonly used data transmission format on mobile platforms. In this example, two Json format file generation and parsing methods are provided.The first method is to
'; private $private_ex = 'this is private!'; protected $protected_ex = 'this should be protected'; public function getErrorCode() { return self::ERROR_CODE; } }
Now, perform json conversion on the instance of this class:
12345
$foo = new Foo; $foo_json = json_encode($foo); echo $foo_json;
The output result is
1
{"public_ex":"this is public"}
As you can see, except the public variable
results
@ Param {String | Number} space (optional) add indentation, spaces, and line breaks to the returned JSON text to make it easier to read
Note:
If the value has the toJSON method, the JSON. stringify function uses the return value of this method.
If the return value of the toJSON method is undefined, no member is converted.
This allows the object to determine its own j son representation.
V
follows:
$ Json = '{"foo": 12345 }';$ Obj = json_decode ($ json );Print $ obj-> {'foo'}; // 12345
In general, json_decode () always returns a PHP Object instead of an array. For example:
The Code is as follows:
$ Json = '{"a": 1, "B": 2, "c": 3, "d": 4, "e": 5 }';Var_dump (json_decode ($ json ));
The result is to
= '{"foo": 12345 }';$ Obj = json_decode ($ json );Print $ obj-> {'foo'}; // 12345
In general, json_decode () always returns a PHP object instead of an array. For example:
The code is as follows:
$ Json = '{"a": 1, "B": 2, "c": 3, "d": 4, "e": 5 }';Var_dump (json_decode ($ json ));
The result is to generate a PHP ob
Jquery parses Json format data and jquery parses json
I learned a little about Json today,JSON(JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. JSO
Work, you need to deal with the other side of the system data exchange problems, using the method of invoking the remote interface, the data format to choose JSON, today to chat about JSON, the main analysis of the JSON data and Java bean transformation between the problem.
One, what is JSON
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.