{"id":528,"date":"2014-09-02T15:18:54","date_gmt":"2014-09-02T07:18:54","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=528"},"modified":"2016-07-15T14:13:20","modified_gmt":"2016-07-15T06:13:20","slug":"afnetwork-2-0%e5%9c%a8%e8%af%b7%e6%b1%82%e6%97%b6%e6%8a%a5%e9%94%99code-1016-%e5%92%8c-3840","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/analysis\/2014\/09\/02\/151854528.html","title":{"rendered":"AFNetwork 2.0\u5728\u8bf7\u6c42\u65f6\u62a5\u9519code=-1016 \u548c 3840"},"content":{"rendered":"<p>\u5728\u8fdb\u884c\u7f51\u7edc\u8bf7\u6c42\u65f6\u51fa\u73b0-1016 \u662f\u56e0\u4e3a\u53ea\u652f\u6301<strong>text\/json\uff0capplication\/json\uff0ctext\/javascript<\/strong><br \/>\n\u4f60\u53ef\u4ee5\u6dfb\u52a0text\/html,\u4e00\u52b3\u6c38\u9038\u7684\u65b9\u6cd5\u662f\u5728AFURLResponseSerialization.h\u91cc\u9762\u641c\u7d22self.acceptableContentTypes\u7136\u540e\u5728\u91cc\u9762\u6dfb\u52a0<br \/>\n@&#8221;text\/html&#8221;,@&#8221;text\/plain&#8221;\u8fd9\u6837\u5c31\u53ef\u4ee5\u89e3\u51b3-1016\u7684\u9519\u8bef\u4e86\u4f46\u662f\u968f\u4e4b\u800c\u6765\u7684\u662f3840\u9519\u8bef<\/p>\n<p>Error Domain=NSCocoaErrorDomain Code=3840 &#8220;The operation couldn\u2019t be completed. (Cocoa error 3840.)&#8221; (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x9152780 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}<br \/>\n\u4f60\u4f1a\u53d1\u73b0\u51fa\u73b0\u6b64\u9519\u8bef,\u600e\u4e48\u529e\u5462,\u6dfb\u52a0\u5982\u4e0b\u8bed\u53e5 \u5c31\u53ef\u4ee5\u89e3\u51b3\u95ee\u9898\u4e86<\/p>\n<p>manger.requestSerializer = [AFHTTPRequestSerializer serializer];<br \/>\nmanger.responseSerializer = [AFHTTPResponseSerializer serializer];<\/p>\n<p>\u662f\u5426\u6210\u529f\u4e86,\u6210\u529f\u4e86\u5427!\u4f46\u662f\u65b0\u95ee\u9898\u51fa\u73b0\u4e86\uff0c\u5f53\u4f60\u7528\u6d4f\u89c8\u5668\u53bb\u8bf7\u6c42\u65f6\u53d1\u73b0\u54cd\u5e94\u5934Content-Type: text\/html;charset=UTF-8 \u662f\u8fd9\u6837\u7684\uff0c\u4f46\u662fafNetwork\u8bf7\u6c42\u662fContent-Type:text\/plain;charset=ISO-8859-1 \u662f\u8fd9\u6837\u7684 \u4e0d\u4e00\u81f4\u4e86\u5427\uff0c\u4e3a\u4ec0\u4e48 pc\u6d4f\u89c8\u5668 \u8bbf\u95ee\u7684 \u548c\u7528afNetwork \u8bbf\u95ee\u7684\u4e0d\u4e00\u81f4\u5462? \u4e0d\u4e86\u89e3\u4ec0\u4e48\u60c5\u51b5?\u63a5\u7740\u53d1\u73b0\u5176\u5b9e\u6dfb\u52a0\u5982\u4e0b\u4e8c\u53e5\u5373\u53ef\uff0c\u4e5f\u4e0d\u7528\u53bb\u4fee\u6539AFURLResponseSerialization.h \u91cc\u9762\u7684\u4e1c\u897f<\/p>\n<p>manger.requestSerializer = [AFHTTPRequestSerializer serializer];<br \/>\nmanger.responseSerializer = [AFHTTPResponseSerializer serializer];<br \/>\n\u628a\u6536\u5230\u7684responseObject \u8f6c\u6362\u4e00\u4e0b \u7f16\u7801 \u5c31OK\u4e86<\/p>\n<p>NSData *doubi = responseObject;<br \/>\nNSString *shabi = [[NSStringalloc]initWithData:doubi encoding:NSUTF8StringEncoding];<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8fdb\u884c\u7f51\u7edc\u8bf7\u6c42\u65f6\u51fa\u73b0-1016 \u662f\u56e0\u4e3a\u53ea\u652f\u6301text\/json\uff0capplication\/json\uff0ctext\/javascript \u4f60\u53ef\u4ee5\u6dfb\u52a0text\/html,\u4e00\u52b3\u6c38\u9038\u7684\u65b9\u6cd5\u662f\u5728AFURLResponseSerialization.h\u91cc\u9762\u641c\u7d22self.acceptableContentTypes\u7136\u540e\u5728\u91cc\u9762\u6dfb\u52a0 @&#8221;text\/html&#8221;,@&#8221;text\/plain&#8221;\u8fd9\u6837\u5c31\u53ef\u4ee5\u89e3\u51b3-1016\u7684\u9519\u8bef\u4e86\u4f46\u662f\u968f\u4e4b\u800c\u6765\u7684\u662f3840\u9519\u8bef Error Domain=NSCocoaErrorDomain Code=3840 &#8220;The operation couldn\u2019t be completed. (Cocoa error 3840.)&#8221; (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x9152780 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.} \u4f60\u4f1a\u53d1\u73b0\u51fa\u73b0\u6b64\u9519\u8bef,\u600e\u4e48\u529e\u5462,\u6dfb\u52a0\u5982\u4e0b\u8bed\u53e5 \u5c31\u53ef\u4ee5\u89e3\u51b3\u95ee\u9898\u4e86 manger.requestSerializer = [AFHTTPRequestSerializer serializer]; manger.responseSerializer [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[18],"class_list":["post-528","post","type-post","status-publish","format-standard","hentry","category-analysis","tag-network"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=528"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/528\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}