How JavaScript parses JSON on how JavaScript parses a JSON object and dynamically assigns a value to a select column representation and dynamically assigns a value to the select list

Source: Internet
Author: User

How the original JavaScript parses a JSON object and dynamically assigns a value to the select list

JSON (Javascriptobject Notation) is a simple data format that is lighter than XML. JSON is a native JavaScript format, which means that working with JSON data in JavaScript does not require any special APIs or toolkits .

The rules of JSON are simple: an object is an unordered collection of "name/value pairs". An object starts with "{" (opening parenthesis) and "}" (the closing parenthesis) ends. Each "name" is followed by a ":" (colon); "' Name/value ' pair ' is separated by", "(comma).

At the time of development Ecshop , it was submitted using an Ajax function from Ecshop itself, which returned a JSON object, such as:

  1. {"Error":0,"Message":"","Content":[{ "id" : " "hdbm" : "0000000024" , "HDMC" : "20140420\u897f\u5b81\u7ad9" , " DQBM ":" 1001 "," Didian " : "\u897f\u5b81\u7ad9" , "Shijian" : "2014-04-20" , "jine" : " , "status" : "1" Span class= "pun" _}]}

At the beginning, I did the parsing and didn't succeed. Always return object

Next look at the parsed example.

  1. var callback = function(res)
  2. {
  3. var json = res. Content;
  4. var array=json;
  5. var sel = document. getElementById(' activity_id ');
  6. If(json= =' null ') {
  7. Sel. Options. Length = 1;
  8. }Else{
  9. Sel. Options. Length = 0;
  10. For(var i=0; i<array. length; i+ +)
  11. {
  12. Sel. Options. Add(Thenew Option(array[i]. HDMC,array[i]. HDBM));
  13. }
  14. }
  15. }

To complete the Ecshop, such as:

How JavaScript parses JSON on how JavaScript parses a JSON object and dynamically assigns a value to a select column representation and dynamically assigns a value to the select list

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.