响应字典中键serialNumbers的错误类型对象。预计NSArray但找到__NSCFString

时间:2013-12-01 23:38:42

标签: php json passbook

我为存折设置了一个Web服务,错误日志正在记录此错误:

获取serial #s任务(对于设备88a9cbef8e318f61,传递类型pass.com.passbook,最后更新(null);使用Web服务url https://)遇到错误:服务器响应格式错误(密钥serialNumbers的类型对象错误在响应字典中。预期NSArray但找到__NSCFString。)

找不到PHP时的代码:

 $updatable_passes_payload['lastUpdated'] = '';
            $updatable_passes_payload['serialNumbers'] = '';
            sendResponse(204, json_encode($updatable_passes_payload), 'text/json');

找到的时间:

 $update_time = date('Y-m-d H:i:s');
            $updatable_passes_payload['lastUpdated'] = $update_time;
            $updatable_passes_payload['serialNumbers'] = json_encode($types);
            sendResponse(200, json_encode($updatable_passes_payload), 'text/json');

网络服务json:

HTTP/1.1 200 OK
Connection: close
Transfer-Encoding: Identity
Content-Type: text/json
X-Powered-By: PHP/5.4.22
Server: Apache mod_fcgid/2.3.10-dev
Date: Sun, 01 Dec 2013 23:25:08 GMT

{"lastUpdated":"2013-12-01 23:25:09","serialNumbers":"[\"102058742\"]"}


i checked this json in a json validator online it returns OK

未找到时返回

HTTP/1.1 204 No Content
Connection: close
Content-Type: text/json
X-Powered-By: PHP/5.4.22
Server: Apache mod_fcgid/2.3.10-dev
Date: Sun, 01 Dec 2013 23:35:17 GMT

出于某种原因,未找到时返回任何json

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

您的问题与您的JSON数组有关。您已将数组封装在引号中,因此它被解释为字符串。

以下内容应该有效:

{"lastUpdated":"2013-12-01 23:25:09","serialNumbers":["102058742"]}