When using json to transmit data in ajax, other data types are not a problem. However, if there is bool type data in the JSON generated by the server, there will be a small problem when the client parses it. The summary is as follows:
The JSON returned by the server is:
{"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":"
"}
where Attributes: IsLink and IsPic are both bool types. How to use them on the client:
document.getElementById("checkbox1").checked = news.IsLink;
The checkbox will be selected, but IsLInk is false and it should not be selected. Why?
Check the reason. JavaScript has three basic data types (string, number, boolean), two reference data types (Object, Array) and two special data types (Null, Undefined ). The following principles apply when converting other types to bool:
The value after the data type is converted to bool
null FALSE
undefined FALSE
Object TRUE
function TRUE
0 FALSE
1 TRUE
Number other than 0 and 1 TRUE
String TRUE
""(empty string) FALSE
At this time, IsLink is a string in JSON "false", so after conversion, the bool type true is obtained.
Solution:
document.getElementById ("checkbox1").checked = news.IsLink=="true";