Mal*_*loc 24 php ios afnetworking
我正在使用AFJSONRequestOperation请求服务器并解析返回的JSON响应,但在解析时,我收到此错误:
NSDebugDescription = "JSON text did not start with array or object and option to allow fragments not set.";
Run Code Online (Sandbox Code Playgroud)
我检查了API,它返回了JSON数据:
header('Content-type: text/json');
$arr[] = array("Message" => "update succeeded");
echo '{"Result":'.json_encode($arr).'}';
Run Code Online (Sandbox Code Playgroud)
知道怎么解决这个问题吗?
编辑
我试图从浏览器调用API并在URL中包含请求,因此我得到了一个有效的JSON响应:
{"Result":[{"Message":"update succeeded"}]}
Run Code Online (Sandbox Code Playgroud)
首先,json_encode整个物体而不是分解成碎片。
其次,除非 $arr 包含多个元素(从上面的示例中不清楚),否则应将其初始化为:
$arr = array("Message" => "update succeeded");
我仍然不确定这里还有什么问题。您应该回显您的应用程序正在接收的内容,这应该表明问题。