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:
- {"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.
- var callback = function(res)
- {
- var json = res. Content;
- var array=json;
- var sel = document. getElementById(' activity_id ');
- If(json= =' null ') {
- Sel. Options. Length = 1;
- }Else{
- Sel. Options. Length = 0;
- For(var i=0; i<array. length; i+ +)
- {
- Sel. Options. Add(Thenew Option(array[i]. HDMC,array[i]. HDBM));
- }
- }
- }
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