NSURLConnection:JSON文本不是以数组或对象开头,而是选项允许未设置片段 [英] NSURLConnection : JSON text did not start with array or object and option to allow fragments not set

查看:223
本文介绍了NSURLConnection:JSON文本不是以数组或对象开头,而是选项允许未设置片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从NSURLConnection中收到以下错误connectionDidFinishLoading

I get the following error from NSURLConnection connectionDidFinishLoading


操作无法完成。(Cocoa error 3840.)( JSON文本
没有以数组或对象和选项开头,以允许片段不是
设置。)UserInfo = 0x7b71dbb0 {NSDebugDescription = JSON文本没有启动带有数组或对象的
和允许片段的选项未设置。}

"The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7b71dbb0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

我使用了以下代码:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
    NSError *error;
    id json = [NSJSONSerialization JSONObjectWithData:_urlData options:kNilOptions error:&error];

    if (error) {
        NSLog(@"Loading Error = %@",error);
    }
}

以下是我的json回复:

The following is my json response :

{  
   "result":"success",
   "details":[  
      {  
         "id":"11531",
         "user_name":"",
         "fullname":"aa",
         "email_address":"aa",
         "user_type":"a",
         "server":"",
         "server_email":"",
         "server_password":"",
         "password":"0cc175b9c0f1b6a831c399e269772661",
         "clean_password":"a",
         "gender":"",
         "ceo_name":"",
         "ceo_picture":"",
         "ceo_contact":"",
         "ceo_contact_pic":"",
         "company_name":"a",
         "freight_company_name":"",
         "freight_company_email":"",
         "company_url":"11531",
         "company_keyword":"",
         "company_description":"",
         "address":"",
         "province":"",
         "postal_code":"",
         "phone_number":"",
         "fax_number":"",
         "website":"",
         "city":"",
         "b_category":"",
         "main_products":"",
         "cellphone":"a",
         "country":"0",
         "states":"",
         "company_status":"1",
         "joindate":"0",
         "varificationcode":"",
         "activation_status":"1",
         "new_email":"",
         "email_activation_status":"",
         "facebook_url":"",
         "twitter_url":"",
         "company_update_status":"0",
         "last_access_date":"0000-00-00",
         "ip_address":"",
         "ip_block":"0",
         "user_id":null,
         "company_id":null,
         "video_url":"",
         "oauth_uid":"",
         "oauth_provider":"",
         "get_color":"",
         "comp_name_size":"13",
         "member_type":"",
         "mark_status":"1",
         "ip_address_intension":"",
         "fbId":"",
         "twitterId":"",
         "profile_picture":"",
         "device_token":""
      }
   ]
}

我试过stackOverflow中的所有解决方案,但仍然是静脉。

I have tried all the solutions in stackOverflow but in vein.

推荐答案

将选项值设置为 NSJSONReadingAllowFragments 而不是 kNilOptions
我已经测试了你的JSON,将它带入本地文件

Set option value to NSJSONReadingAllowFragments instead of kNilOptions I have tested your JSON taking it in a local file

id json = [NSJSONSerialization JSONObjectWithData:contentOfLocalFile
                                                options:NSJSONReadingAllowFragments
                                                  error:&deserializingError];

这篇关于NSURLConnection:JSON文本不是以数组或对象开头,而是选项允许未设置片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆