AFHTTPRequestOperationManager*manger=[AFHTTPRequestOperationManager manager];
    NSDictionary*dic=[[NSDictionary alloc]initWithObjectsAndKeys:_phonenumber.text,@"phonenumber",_passWord.text,@"password",@"asd",@"username", nil];
    manger.responseSerializer=[AFJSONResponseSerializer serializer]
    ;
    
    manger.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
 
    NSDictionary*dd=[[NSDictionary alloc]initWithObjectsAndKeys:dic ,@"user", nil];
    NSData*data=[NSJSONSerialization dataWithJSONObject:dd options:NSJSONWritingPrettyPrinted error:nil];
    NSString*url=@"http://192.168.2.121:8080/phonebook/regist.do";
        [manger.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [manger POST:url parameters:(NSData*)data success:^(AFHTTPRequestOperation *operation, id responseObject){
    NSLog(@"JSON: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error){
    NSLog(@"%@",error);
    }
    ];
代码如上
报错如下  哪位大神知道告诉下小弟
2015-07-06 19:16:42.287 PhoneBook[8541:489588] Error Domain=NSCocoaErrorDomain Code=3840 "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=0x7f9332f27e20 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set., NSUnderlyingError=0x7f9332d38880 "Request failed: bad request (400)"}

解决方案 »

  1.   

    服务器端返回的文本有问题,无法转换为json对象,就是说服务器端返回的json文本格式不对,解析不了,跟客户端没太大关系
      

  2.   

    网搜json在线解析,然后将返回的json格式看是否能解析,如果不能解析就是服务端问题,如果能解析就是客户端问题,打断点走代码吧
      

  3.   

    JSON text did not start with array or object and option to allow fragments not set.
      

  4.   

    你在AFURLResponseSerialization.m中的222行加入@"text/html",@"text/plain"试一试,如果请求报错为code=-1064你需要在请求方法里面加上
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];这样应该能旧居问题了,如果还是解决不了,那肯定是后台的问题。