Get json file data through Ajax in Jquery, and get json through jqueryajax

Source: Internet
Author: User

Get json file data through Ajax in Jquery, and get json through jqueryajax

1. JSON (JavaScript Object Notation): javaScript Object Notation;

It is a syntax for storing and exchanging text information, which is smaller, faster, and easier to parse than xml.

2. Basic JSON writing format: Name/value pair. Example: "Student": "Tom"

The Json value can be:

For example (object): {"name": "tom", "age": 23}

(Array ):

1 {2 "Zhang San": [3 {"surname": "Zhang"}, 4 {"name", "3"}, 5 {"age ", 23} 6] 7}

 

Note: ① writing a JSON array is similar to writing a String array in java. It is worth noting that JSON is a name/value pair.

② The string format is double quotation marks, which cannot be used as single or double quotation marks in JavaScript.

③ No matter the array or object, the last value cannot be followed by a comma. Otherwise, a problem may occur.

After testing JSON data in the Google browser console, neither ② nor ③ will report any errors and can be read. However, when I use ajax in jquery to obtain data in the JSON file, an error may occur. The specific cause cannot be answered.

 

The following is the debugging result on the Google browser Console (note that none of the above ② and ③ are met ).

 

The basic call to json data is the call to arrays and objects.

 

3. Obtain the Json file using a specific example.

Create a. json file.

{"List": [{"name": "c", "url": "demo2.html" },{ "name": "list22", "url ": "demo2.html" },{ "name": "list33", "url": "demo2.html" },{ "name": "list44", "url ": "demo2.html" },{ "name": "list55", "url": "demo2.html" },{ "name": "list66", "url ": "demo2.html"}], "list1": [{"name": "I am the second ul 1", "url": "demo2.html" },{ "name ": "I am the second ul 2", "url": "demo2.html" },{ "name": "I am the second ul 3", "url ": "demo2.html" },{ "name": "I am the second ul 4", "url": "demo2.html" },{ "name ": "I am the second ul 5", "url": "demo2.html" },{ "name": "I am the second ul 6", "url ": "demo2.html"}]}

 

Write in html:

<! DOCTYPE html> 

 

View:

Figure 3-1

Figure 3-2

 

The final effect is as follows:

The temperament ul list can also be set based on other Css styles to achieve more beautiful results.

 

 

 

 

 

 

 

 

 

 

 

 

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.