2

我正在尝试输出一些 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 分析代码

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

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

谢谢...

4

1 回答 1

1

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

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

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

于 2013-10-09T03:21:16.180 回答