JSON正在丢失PHP中的格式

时间:2014-03-06 05:00:40

标签: php json

我有一个返回格式化JSON的网址。问题是,当我回显$ json时,json正在丢失其格式。我该如何避免

我这样做

$query_string_full = http://this_is_a_dummyString.htm?key=123&ID=abc123;

$json = file_get_contents($query_string_full);
$obj = json_decode(stripslashes($json));

echo $obj;

这是输出 http://soumghosh.com/otherProjects/phpDataOperation/eventcCalendar/ajax.php

我发现了这种性质的几个类似的问题但不幸的是,它们都没有真正起作用。一个人正在使用striplashes。也许我没有正确使用它?

1 个答案:

答案 0 :(得分:1)

你回应的内容应该是一个对象或一个数组,因为这是json_decode()将返回的内容。

试试这个:

$query_string_full = http://this_is_a_dummyString.htm?key=123&ID=abc123;

$json = file_get_contents($query_string_full);
$obj = json_decode($json);
echo '<pre>'. json_encode($obj, JSON_PRETTY_PRINT) .'</pre>';

Example