Other data types are not an issue when using JSON to pass data in Ajax, but if there is a bool type of data in the server-side generated JSON, there is a small problem when parsing to the client, summarized as follows:
The JSON returned by the server is:
The code is as follows:
{"TypeID": [1037], "Title": "Hebei software vocational and Technical College", "Intro": "", "Islink": "false", "Linkurl": "http://www.hbsi.edu.cn", "Ispic": " True "," Picture ":"/newsimages/hbsi.jpg "," Content ":" <p><br></p> "}
Where properties: Islink and Ispic are all bool types, the client uses the method:
The code is as follows:
document.getElementById ("CheckBox1"). Checked = news. Islink;
check box is selected, but Islink is false, this should not be selected, why?
For the reasons, JavaScript has three basic data types (string strings, numeric number, Boolean Boolean), two reference data types (object, array), and two special data types (Null, Undefined). Other types of conversions to the bool type have the following principles:
Value after the data type is converted to bool
Null FALSE
Undefined FALSE
Object TRUE
function TRUE
0 FALSE
1 TRUE
0, 1 digits outside TRUE
String TRUE
"" (empty string) FALSE
At this point, Islink is the string "false" in JSON, so the bool type is true after conversion.
Treatment methods:
The code is as follows:
document.getElementById ("CheckBox1"). Checked = news. islink== "true";
JSON data types and how to pass bool type data processing