简体   繁体   English

JSONKit 无法从 php 解析简单的 JSON?

[英]JSONKit failed to parse simple JSON from php?

I am using JSONKit in my iOS app.我在我的 iOS 应用程序中使用 JSONKit。 It loads an extremely simple JSON served by my php file:它加载了一个极其简单的 JSON,由我的 php 文件提供:

http://staging.comwerks.net/terrence/ecitizen/article.php http://staging.comwerks.net/terrence/ecitizen/article.php

somehow, it is producing an error: "Unexpected token, wanted '{', '}', '[', ']', ',', ':', 'true', 'false', 'null', '"STRING"', 'NUMBER'.}不知何故,它产生了一个错误:“意外的令牌,想要'{','}','[',']',',',':','true','false','null',' “字符串”,“数字”。}

When I try to use http://jsonlint.com/ to lint my URL above.当我尝试使用http://jsonlint.com/对上面的 URL 进行 lint 时。 It is giving a similar error complaining about the open bracket!它给出了一个类似的错误抱怨开括号!

my php cant be more simple:我的 php 再简单不过了:

<?php
header('Content-type: application/json');
$json = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($json);
?>

It might be complaining about the Unicode byte order mark at the start of the response.它可能会抱怨响应开头的 Unicode 字节顺序标记。 If I copy and paste the output into the linter, it validates.如果我将 output 复制并粘贴到 linter 中,它就会生效。 It's probably at the start of your article.php file.它可能在您文章的开头。php 文件。 Your text editor should have an option to save without it (possibly in the Save As... dialog).您的文本编辑器应该有一个不保存的选项(可能在“另存为...”对话框中)。

http://en.wikipedia.org/wiki/Byte_order_mark http://en.wikipedia.org/wiki/Byte_order_mark

I agree with Nick.我同意尼克的观点。 When I pulled the json directly to a file, my editor said the encoding was UTF-8 with BOM.当我将 json 直接拉到一个文件时,我的编辑说编码是 UTF-8 和 BOM。

In addition the JSON validator you used gives me this error:此外,您使用的 JSON 验证器给我这个错误:

JSON Parse error: Unrecognized token '?'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM