Step 1 without dragging controls on ASP. NET-Understanding JSON

Source: Internet
Author: User

Originally, I wanted to record the teaching video. Uncle Lin's school recorded the first episode. It was just a playing event downstairs. The disturbance was too high. Let's write it! This time I will talk about a necessary step away from the ASP. NET control. Use JSON and JQuery to get JSON!

The experts skipped and wrote it to the learners. This post assumes that you will use JQuery (JQ is so popular that you should not have learned it at least! I have never learned this before)

What is JSON?

Explanation from W3School:

  • JSON refers to the JavaScript Object Notation (JavaScript Object Notation)
  • JSON is a lightweight text data exchange format.
  • JSON is independent of the Language *
  • JSON is self-descriptive and easy to understand.

Needless to say, the straightforward explanation is a piece of text, which can be used to represent a piece of structure, similar to C # and JAVA classes, but the values are included. You can see a JSON example:

JSONObject = {"name": "Uncle Lin" "street": "88, XX Road, Fuzhou City" "age": 29 "phone": "18933883388 "};

When you need to call JSONObject. name, you can get "Uncle Lin ".

The advantage of JSON is that it is faster to read than XML, and now basically Ajax interaction data depends on JSON. Note that the "name/value" pair in the middle of JSON is in the format of name: value, which is a half-width colon.

Well, after JSON is finished, it is really about this content, but how can it be used? If I don't say how to use it, I will only talk about JSON?

Let's talk about how to use JQuery to obtain JSON. Assume that the data acquisition address is api. aspx, and then assume that you directly access the api. A string obtained by aspx is the JSON defined above. So:

var url='api.aspx';
$.getJSON(url, "#txtName""#txtAge"

The function that follows indicates the function to be executed after obtaining the data. That is to say, after the data is obtained successfully, the data is the JSON string obtained. In this case, the value can be obtained based on the defined name.

If there is no asynchronous concept, you should note that it takes time to obtain the data. Here, there is an asynchronous concept. That is to say, the subsequent function will be executed only when the data is returned, that is, you need to wait for the specific time, depending on the running environment.

With the above examples, you can imagine it.

For example, I used to create a detailed page of a specific content in ASP. NET (for example, the details of student information, forgive me for using this example ). The general method is to create a StudentInfo. aspx page, drag several controls, obtain detailed information from the database based on the input Id, and then bind the value to the control during Page_Load.

With the above method, you can basically skip the server control! You can use HTML tags. The data is displayed in an address. The detailed page uses JQuery to retrieve JSON data. After obtaining the data, you can assign a value to the HTML Tag.

As for how to retrieve list data, how or insert data. Post these questions later. I wish my students of ASP. NET to get rid of it as soon as possible and only drag controls.

The. NET course that best meets enterprise needs is in yiheng Education

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.