When JSON is used to transmit data in Ajax, other data types are not a problem. However, if the JSON generated by the server contains bool data, a small problem occurs during client parsing, summary:
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":"<p><br></p>"}
Here, attributes: islink and ispic are both of the bool type. How to use them on the client:
Document. getelementbyid ("checkbox1"). Checked = News. islink; check box selected, but islink is false. This check box should not be selected. Why?
Check the cause. Javascript has three basic data types (string, number, and Boolean) and two reference data types (Object and array) and two special data types (null and undefined ). The following principles apply when converting other types to the bool type:
Data Type |
Value After bool Conversion |
Null |
False |
Undefined |
False |
Object |
True |
Function |
True |
0 |
False |
1 |
True |
Numbers other than 0 and 1 |
True |
String |
True |
"" (Null String) |
False |
In this case, islink is the string "false" in JSON, so the bool type is true after conversion.
Solution:
Document. getelementbyid ("checkbox1"). Checked = News. islink = "true ";