Wrong type object for key serialNumbers in response dictionary. Expected NSArray but found __NSCFString

357 Views Asked by At

i have a web service set up for passbook the error log is logging this error:

Get serial #s task (for device 88a9cbef8e318f61, pass type pass.com.passbook, last updated (null); with web service url https://) encountered error: Server response was malformed (Wrong type object for key serialNumbers in response dictionary. Expected NSArray but found __NSCFString.)

the code in PHP when is not found :

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

when is found:

 $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');

the web service 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

when is not found it returns

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

for some reason is not returning any json when not found

any help will be appreciated

1

There are 1 best solutions below

0
On BEST ANSWER

Your issue is with your JSON array. You have encapsulated your array in quotes so it is being interpreted as a string.

The following should work:

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