PHP json_encode() 使用 <head> 和 <body> 标签打印
PHP json_encode() get printed with <head> and <body> tags
当我回显 json_encode 时,结果包含在 <html>
<head>
和 <body>
标记中。文件保存为 .php 文件
这是文件的代码(减去数据库连接)
header("Content-Type: application/json");
// connect to db...query etc...
$arr = array();
while($row = mysqli_fetch_assoc($result)) {
$arr[] = $row;
}
echo '{"members":'.json_encode($arr).'}';
如何只输出 json 因为信息将在 iOS 应用程序中使用?
Chrome 检查器向您展示 Chrome 正在做什么来解释和显示文件(即,将数据格式化为 Web page/html-file,并包括扩展行为),这是在 Chrome 中打开的 .json-file 的示例(脚本由扩展名插入):
查看源代码本身 (view-source:http://url.com/file.json
) 应该会显示原始数据,这就是您的应用程序将看到的内容。
当我回显 json_encode 时,结果包含在 <html>
<head>
和 <body>
标记中。文件保存为 .php 文件
这是文件的代码(减去数据库连接)
header("Content-Type: application/json");
// connect to db...query etc...
$arr = array();
while($row = mysqli_fetch_assoc($result)) {
$arr[] = $row;
}
echo '{"members":'.json_encode($arr).'}';
如何只输出 json 因为信息将在 iOS 应用程序中使用?
Chrome 检查器向您展示 Chrome 正在做什么来解释和显示文件(即,将数据格式化为 Web page/html-file,并包括扩展行为),这是在 Chrome 中打开的 .json-file 的示例(脚本由扩展名插入):
查看源代码本身 (view-source:http://url.com/file.json
) 应该会显示原始数据,这就是您的应用程序将看到的内容。