2012-03-26 160 views
3

我有一個JSON字符串(外部文件),它有一個可以具有FALSE或TRUE作爲值的元素。在文件中,真實或虛假的IS在那裏。然而,在我使用json_decode之後,真或假會丟失。爲什麼?json_decode數據丟失

的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。

+3

顯示代碼/ JSON。 – 2012-03-26 14:04:26

+0

來自你的代碼的例子會有所幫助。 – h00ligan 2012-03-26 14:05:30

+2

您希望得到一個答案,但不向我們展示您的JSON或用於檢查json_decode之後值是否仍然存在的代碼? – Paulpro 2012-03-26 14:05:31

回答

3

print_r不顯示類型,所以它將顯示0代表假,1代表真。 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) 
}