php - NSDebugDescription = "JSON text did not start with array or object and option to allow fragments not set.";

标签 php ios afnetworking

我正在使用 AFJSONRequestOperation 请求服务器并解析返回的 JSON 响应,但是在解析时,我得到了这个错误:

NSDebugDescription = "JSON text did not start with array or object and option to allow fragments not set.";

我检查了 API,它正在返回 JSON 数据:

header('Content-type: text/json');
$arr[] = array("Message" => "update succeeded");
echo '{"Result":'.json_encode($arr).'}';

知道如何解决这个问题吗?

编辑

我尝试从浏览器调用 API 并将请求包含在 url 中,因此我得到了有效的 JSON 响应:

{"Result":[{"Message":"update succeeded"}]}

最佳答案

首先,json_encode 整个对象,而不是分成几 block 。

其次,除非 $arr 包含多个元素(从上面的示例中看不清楚),否则应该这样初始化:

$arr = array("消息"=> "更新成功");

我仍然不确定这里还有什么问题。您应该回显您的应用收到的内容,这应该表明问题所在。

关于php - NSDebugDescription = "JSON text did not start with array or object and option to allow fragments not set.";,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15456396/

相关文章:

java - 带有自定义适配器的 ListView 图像和文本

ios - 如何从代码中以编程方式设置 uiimageview 的大小以在我的 swift 应用程序中覆盖全屏?

ios - Xcode 8's simulator won' t 工作

ios - 请求错误代码为 999 的 AFNetworking

ios - 使用 AFNetworking 不需要缓存 GET 请求

ios - Objective-C 中的渐进式下载和视频播放

php - if () { } 和 if () 的区别 : endif;

php - 突然 pdf 不再上传 (php/mysql)

Javascript 变量似乎是静态的

ios - 触发 Apple Watch 通知