PHP 标头 JSON 显示奇怪的东西


PHP Header JSON showing weird thing

我正在尝试输出一些 json 代码并对其进行编码......我得到了一些奇怪的结果..

这是我的php代码和标题,所以当我使用我的应用程序阅读时,它会将其视为json内容类型而不是html

header('Content-Type: application/json');
echo "{'"data'":".json_encode($showArray) . "}";

输出是这样的:

{"data":[{"id":"4628","name":"NCIS","season":"11"},{"id":"21934","name":"NCIS: Los Angeles","season":"5"},{"id":"24591","name":"The Real NCIS","season":"1"},{"id":"34498","name":"NCIS: Red","season":"1"},{"id":"38017","name":"NCIS: New Orleans","season":"1"},{"id":"3039","name":"Charmed","season":"8"},{"id":"6125","name":"The Real World","season":"28"},{"id":"32724","name":"Da Vinci's Demons","season":"2"},{"id":"27924","name":"The Franchise","season":"2"},{"id":"6218","name":"The Streets of San Francisco","season":"5"},{"id":"3253","name":"Da Vinci's Inquest","season":"7"},{"id":"6862","name":"Da Vinci's City Hall","season":"1"},{"id":"32034","name":"Oddities: San Francisco","season":"2"},{"id":"14884","name":"San Francisco International Airport","season":"1"},{"id":"2616","name":"Animal Cops: San Francisco","season":"1"},{"id":"5208","name":"Sir Francis Drake","season":"1"},{"id":"29590","name":"Easy Chinese","season":"2"},{"id":"5583","name":"The Arlene Francis Show","season":"1"},{"id":"26665","name":"Jancis Robinson's Wine Course","season":"1"},{"id":"17968","name":"Foul Play","season":"1"}]}
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

如果我不做标题,我没有 hostin24 anlaystic 代码

有人知道为什么显示 Hosting24 分析代码吗? 这是服务器添加它吗?

如果是这样..有人推荐免费的PHP服务器吗?

谢谢。。。

看起来像主机设置的自动追加。您可以尝试将exit;放在 PHP 脚本的末尾,以防止它到达发生自动追加的末尾。

有关类似问题,请参阅此处:Webhoster插入了一个破坏我的代码的javascript如何删除它?

编辑:我应该注意,根据您的主机授予您的访问级别,您可能可以使用其他选项(不那么黑客(。阅读上面的链接。