take a look at how the client uses JavaScript to process data in JSON format. Assume that the JSON data returned by the server is as follows:
{"Name": "Michael", "address ":{ Quot; city quot;: quot; Beijing quot;, quot; street quot;: quot; ChaoyangRoad quot;, quot; postcode quot;: 100025}}
Using a simple JavaScript method, we can see how the client expresses J
There are many conversion methods between Json characters and Json objects. Next we will introduce them one by one. If you are interested, please refer to the following:
1> conversion modes supported by jQuery plug-in:
The Code is as follows:
$. ParseJSON (jsonstr); // jQuery. parseJSON (jsonstr), which can convert a json
JSON Basics
Simply put, JSON can convert a set of data represented in a JavaScript object into a string, which can then be easily passed between functions, or in an asynchronous application passing a string from a WEB client to a server-side program. The string looks a bit odd (see a couple of examples later), but JavaScript is easy to explain, and
JSON Basics
Simply put, JSON can convert a set of data represented in a JavaScript object into a string, which can then be easily passed between functions, or in an asynchronous application passing a string from a WEB client to a server-side program. The string looks a bit odd (see a couple of examples later), but JavaScript is easy to explain, and
name of the first entry in the programmers list, just use the following code in JavaScript:
People.programmers[0].lastname;
Note that the array index is zero-based. So, this line of code first accesses the data in the people variable, moves to the entry called programmers, moves to the first record ([0]), and finally accesses the value of the LastName key. The result is the string value "McLaughlin".
Here are several examples of using the same variable.
Copy Code code as follows:
JSON (JavaScriptObjectNotation) is a lightweight data exchange format. JSON uses a language-independent text format. These features make JSON an ideal Data Exchange Language, JSON (JavaScript Object Notation), a lightweight data exchange format. JSON uses a language-independ
:
Var objs = [{id: 1, name: 'n' _ 1'}, {id: 2, name: 'n' _ 2'}];Alert (objs [0]. id );In this way, the object array objs is defined. It contains two objects and can be accessed using indexes. For example, objs [0] Will reference the first object. Here you may have thought about the format of the string returned by the server, but the string is a string after all, and we need to convert it to a variable that can be operated by JS. This uses the eval fu
. count = 10; // or obj ["count"] = 10}
The modified JSON.
4. delete data in JSON
Now we can delete the count data from JSON. The Code is as follows:
function Delete() { delete obj.count; }
Deleted JSON
You can see that count has been deleted from the JSON
JSON Basics
Simply put, JSON can convert a set of data represented in a javascript object to a string, and then it can be easily passed between functions, or asynchronously applied.ProgramTransmits the string from the Web Client to the server-side program. This string looks a bit odd (several examples will be seen later), but javascript can easily explain it, a
JavaScript toolkits or APIs.
modifying JSON data
Just as you can access data with dots and parentheses, you can easily modify the data in the same way:
After you convert a string to a JavaScript object, you can modify the data in the variable like this.
Convert back to String
Of course, if you can't easily
JSON Basics
Simply put, JSON can convert a set of data represented in a JavaScript object to a string, and then it can be easily passed between functions, alternatively, the string is transmitted from the Web Client to the server in an asynchronous application. This string looks a bit odd (several examples will be seen later), but JavaScript can easily explain it
Thanks to JS's native support for JSON, JSON is widely used for data transmission in many projects. How can we convert data from a Java object to a JSON object? How can we convert the foreground JSON object to a Java object for pr
JQuery. parseJSON (json) converts a JSON string to a js object, and the jquery string to json
Overview
Accepts a JSON string and returns the parsed object.
Inputting a malformed JSON string throws an exception. For example, the following are malformed
JSON data Format (original URL)JSON (JavaScript Object Notation) is a lightweight data interchange format. JSON takes a completely language-independent text format, which makes JSON an ideal data exchange language. Easy to read and write, but also easy to machine parse and generate.The infrastructure
The first step: Get a JSON interface that can be obtained from a URL address
Step two: Take the JSON string through file_get_contents
Step three: Convert a JSON-formatted string (object) into an array,
Json_decode (
Json,tRue) number of arguments :
DataTable to Json string (using Newtonsoft. Json. dll), newtonsoft. json. dllDataTable to Json string (using Newtonsoft. Json. dll)
When you need to convert the DataTable into a Json s
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.