ios - [__NSDictionaryI bytes]: unrecognized selector sent to instance 0x7faa75501220 -
i want json data block, failed.
the internet request is
[nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue mainqueue] completionhandler:^(nsurlresponse *response, nsdata *dataresult, nserror *connectionerror) { if (!connectionerror) { if (successblock) { //nsstring* str = [[nsstring alloc] initwithdata:dataresult encoding:nsutf8stringencoding]; //nslog(@"response data: %@", str); nsdictionary *json = [[nsdictionary alloc]init]; json = [nsjsonserialization jsonobjectwithdata:dataresult options:kniloptions error:nil]; successblock(json); } } else { if (failureblock) { failureblock(connectionerror); } } }];
the successblock defined this:
typedef void(^httprequestsuccessblock)(id responseobject); typedef void(^httprequestfailblock)(nserror *error);
i can
dataresult
in1
, translate nsstring, ,nslog
it,json
format.
but when run code, crashed , shows following errors:
2017-08-21 09:43:22.258 shopiphonedemo[24397:5799646] -[__nsdictionaryi bytes]: unrecognized selector sent instance 0x7faa75501220 2017-08-21 09:43:22.264 shopiphonedemo[24397:5799646] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nsdictionaryi bytes]: unrecognized selector sent instance 0x7faa75501220'
update stack trace:
2017-08-21 09:43:22.258 shopiphonedemo[24397:5799646] -[__nsdictionaryi bytes]: unrecognized selector sent instance 0x7faa75501220 2017-08-21 09:43:22.264 shopiphonedemo[24397:5799646] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nsdictionaryi bytes]: unrecognized selector sent instance 0x7faa75501220' *** first throw call stack: ( 0 corefoundation 0x0000000105e8cb0b __exceptionpreprocess + 171 1 libobjc.a.dylib 0x00000001058f1141 objc_exception_throw + 48 2 corefoundation 0x0000000105efc134 -[nsobject(nsobject) doesnotrecognizeselector:] + 132 3 corefoundation 0x0000000105e13840 ___forwarding___ + 1024 4 corefoundation 0x0000000105e133b8 _cf_forwarding_prep_0 + 120 5 foundation 0x00000001054281a1 -[_nsjsonreader findencodingfromdata:withbomskiplength:] + 46 6 foundation 0x0000000105428087 -[_nsjsonreader parsedata:options:] + 58 7 foundation 0x0000000105427fbb +[nsjsonserialization jsonobjectwithdata:options:error:] + 139 8 shopiphonedemo 0x0000000104cc4e2d __24-[appdelegate yoututest]_block_invoke + 77 9 shopiphonedemo 0x0000000104cbfc3f __62-[txqcloudfrsdk sendrequest:mothod:successblock:failureblock:]_block_invoke + 271 10 cfnetwork 0x0000000108a045ae __67+[nsurlconnection sendasynchronousrequest:queue:completionhandler:]_block_invoke_2 + 161 11 foundation 0x00000001053fb3b7 __nsblockoperation_is_calling_out_to_a_block__ + 7 12 foundation 0x00000001053fb0bb -[nsblockoperation main] + 101 13 foundation 0x00000001053f9877 -[__nsoperationinternal _start:] + 627 14 foundation 0x00000001053f55fc __nsoqschedule_f + 198 15 libdispatch.dylib 0x000000010940905c _dispatch_client_callout + 8 16 libdispatch.dylib 0x00000001093ea40b _dispatch_main_queue_callback_4cf + 411 17 corefoundation 0x0000000105e51909 __cfrunloop_is_servicing_the_main_dispatch_queue__ + 9 18 corefoundation 0x0000000105e17ae4 __cfrunlooprun + 2164 19 corefoundation 0x0000000105e17016 cfrunlooprunspecific + 406 20 graphicsservices 0x000000010b4bba24 gseventrunmodal + 62 21 uikit 0x0000000106999134 uiapplicationmain + 159 22 shopiphonedemo 0x0000000104cd0eff main + 111 23 libdyld.dylib 0x000000010945565d start + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception
the json
nslog is:
{"errorcode":0,"errormsg":"ok","session_id":"","name":"陈佳佳","name_confidence_all":[99,99,99],"sex":"女","sex_confidence_all":[99],"nation":"汉","nation_confidence_all":[99],"birth":"1985/9/11","birth_confidence_all":[100,100,100,100,100,100,100,100,100],"address":"福建省尤溪县汤川乡汤三村16号","address_confidence_all":[99,99,99,99,99,99,99,99,99,99,99,99,99,99,99],"id":"350426198509113027","id_confidence_all":[100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100],"frontimage":"","frontimage_confidence_all":[],"watermask_confidence_all":[],"valid_date_confidence_all":[],"authority_confidence_all":[],"backimage_confidence_all":[],"detail_errorcode":[],"detail_errormsg":[]}
i use json editor format is:
{ "errorcode": 0, "errormsg": "ok", "session_id": "", "name": "陈佳佳", "name_confidence_all": [ 99, 99, 99 ], "sex": "女", "sex_confidence_all": [ 99 ], "nation": "汉", "nation_confidence_all": [ 99 ], "birth": "1985/9/11", "birth_confidence_all": [ 100, 100, 100, 100, 100, 100, 100, 100, 100 ], "address": "福建省尤溪县汤川乡汤三村16号", "address_confidence_all": [ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 ], "id": "350426198509113027", "id_confidence_all": [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ], "frontimage": "", "frontimage_confidence_all": [], "watermask_confidence_all": [], "valid_date_confidence_all": [], "authority_confidence_all": [], "backimage_confidence_all": [], "detail_errorcode": [], "detail_errormsg": [] }
what have tried do:
- i try make
mutablecopy
json
, doesn't working. - i try change
id
nsdictionary
, doesn't working either.
might dealing nsarray
rather nsdictionary
. it's better handle both of cases.
id json = [nsjsonserialization jsonobjectwithdata:dataresult options:kniloptions error:nil]; if ([json iskindofclass:[nsarray class]]) { nslog(@"its array!"); nsarray *jsonarray = (nsarray *)json; nslog(@"jsonarray - %@",jsonarray); } else { nslog(@"its dictionary"); nsdictionary *jsondictionary = (nsdictionary *)json; nslog(@"jsondictionary - %@",jsondictionary); }
Comments
Post a Comment