2013-10-25 25 views
0

我測試了一些像素火災,並遇到以下問題。我有一個頁面請求的信息:將安全json轉換爲「常規」片段

<? 
$pixel = file_get_contents("http://127.0.0.1/api/v1/pixel/preq/pixel/10102.json"); 
echo $pixel; 

將返回:

{"code":200,"data":"<script>\r\nalert(\"Cool JS Pixel\");\r\n<\/script>"} 

不過,我有兩個問題,其中第一個是「安全」 \r\n逃到/以及如果我嘗試

<? 
$pixel = file_get_contents("http://127.0.0.1/api/v1/pixel/preq/pixel/10102.json"); 
echo json_decode($pixel); 

我得到以下錯誤:

字符串解碼
Catchable fatal error: Object of class stdClass could not be converted to string in plugins\plg_pixelwise\test.php on line 3 

回答

4

json_decode返回一個對象或數組,如果給出可選的第二個參數true。如果對象沒有提供__toString方法,只有字符串或數字(你可以回顯數組,但他們只是打印「數組」),你不能回顯對象。

嘗試:

var_dump(json_decode($pixel)); 
+0

現在好了,我覺得很傻,是偉大的工作。謝謝。 –