我有一个JSON字符串(外部文件),其元素可以是FALSE或TRUE作为值。在文件中,那里是真或假。但是,在我使用json_decode之后,会丢失true或false。为什么呢?
JSON是有效的,它是由许多
块构成的{
"surroundedDebuff":true,
"citizenId":108981,
"citizenship":19,
"berserk":true,
"defenderSide":false,
"weapon":0,
"time":"25-03-2012 16:07:13:442",
"damage":65
}
(这反复多次),检查是一个简单的print_r。
答案 0 :(得分:3)
print_r不显示类型,因此它将显示0表示false,1表示true。 var_dump会显示这些值实际上是布尔值。
$decoded = json_decode('{"surroundedDebuff":true,"citizenId":108981,"citizenship":19,"berserk":true,"defenderSide":false,"weapon":0,"time":"25-03-2012 16:07:13:442","damage":65}');
print_r($decoded);
var_dump($decoded);
输出:
stdClass Object
(
[surroundedDebuff] => 1
[citizenId] => 108981
[citizenship] => 19
[berserk] => 1
[defenderSide] =>
[weapon] => 0
[time] => 25-03-2012 16:07:13:442
[damage] => 65
)
object(stdClass)#1 (8) {
["surroundedDebuff"]=>
bool(true)
["citizenId"]=>
int(108981)
["citizenship"]=>
int(19)
["berserk"]=>
bool(true)
["defenderSide"]=>
bool(false)
["weapon"]=>
int(0)
["time"]=>
string(23) "25-03-2012 16:07:13:442"
["damage"]=>
int(65)
}