json_decode数据丢失 [英] json_decode data loss
本文介绍了json_decode数据丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JSON字符串(外部文件),该字符串具有一个元素,该元素可以具有FALSE或TRUE作为值.在文件中,是对是错.但是,在我对它使用json_decode之后,true或false都将丢失.为什么?
I have a JSON string (external file) which has an element which can either have FALSE or TRUE as a value. In the file, the true or false IS there. However, after I use json_decode on it, the true or false is lost. Why?
JSON是有效的,它由
The JSON is valid, it is made from many blocks of
{
"surroundedDebuff":true,
"citizenId":108981,
"citizenship":19,
"berserk":true,
"defenderSide":false,
"weapon":0,
"time":"25-03-2012 16:07:13:442",
"damage":65
}
(重复多次),检查是一个简单的print_r.
(this repeated many times), the checking is a simple print_r.
推荐答案
print_r 不显示类型,因此它将显示0(代表false)和1(代表true). var_dump 将显示这些值实际上是布尔值.
print_r doesn't show types, so it will display 0 for false and 1 for true. var_dump will show that the values are actually booleans.
$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)
}
这篇关于json_decode数据丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文