PHP标头JSON显示奇怪的事情

时间:2013-10-09 03:16:40

标签: php json

我正在尝试输出一些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 Anlystics Code正在展示?是这个服务器添加它?

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

谢谢......

1 个答案:

答案 0 :(得分:1)

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

请点击此处查看类似问题: Webhoster inserts a javascript which brokes my code how to remove it?

编辑: 我应该注意,根据您的主机授予您的访问级别,您可以使用其他选项(更少hacky)。阅读以上链接。