我正在测试我的一些像素触发,我有以下问题。我有一个页面请求信息:
<?
$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
json_decode
返回一个对象,或者一个数组,如果你给可选的第二个参数true
。如果对象不提供__toString方法,则无法回显对象,只能提供字符串或数字(您可以回显数组,但它们只打印"Array")。
尝试:
var_dump(json_decode($pixel));