I call a php file to get some informations from my database. When I parse my data I discovered a problem with JSON parse. I have following DebugLog.
"N_[“IsFather”]=0 N*[“IsFather”].AsBool=True "*_
How is that possible? Why returns AsBool a true even though the string value is 0??
Well, if you coerce the number 0 to a boolean, you should get false. However, if you coerce the string “0” to a boolean, you get true (only the empty string converts to false, IIRC). And since raw JSON is a string, I’m not particularly surprised that you could get that result.
Weak typing is evil. You can’t do anything safe with data if you don’t know what its type is; I think languages that encourage you to pretend otherwise are profoundly misguided.
If you want to treat “IsFather” as a boolean value, I recommend you assign it a boolean value in the first place (not a numeric one).
Thank you for the explaination. I have changed it now to AsInt and then use an if statement to set my boolean variable