- [_ NSInlineData objectForKey:]:无法识别的选择器发送到实例0x7e351cc0'

时间:2015-05-18 10:39:24

标签: ios afnetworking

我正在尝试从我成功登录的详细信息中提取userID。这是我的代码`

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
      manager.requestSerializer = [AFHTTPRequestSerializer serializer];
      manager.responseSerializer=[AFHTTPResponseSerializer serializer];

      [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

      manager.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@"text/html"];


      NSString *str=[NSString stringWithFormat:@"{\"username\":\"%@\",\"password\":\"%@\"}",self.usernameTextField.text,self.PswdTextField.text];
      NSDictionary *param=@{@"params":str};


      [manager POST:@"URL" parameters:param

            success:^(AFHTTPRequestOperation *operation, id responseObject) {
                  NSLog(@"responseobject=%@ success=%@",responseObject,operation.responseString);

                NSLog(@"success=%@",[responseObject objectForKey:@"userinfo"]);

我的O / P:

responseobject=<7b22636f 6465223a 302c2275 73657269 6e666f22 3a7b2269 64223a22 31373222 2c226669 7273746e 616d6522 3a224179 75736822 2c226c61 73746e61 6d65223a 22477570 7461222c 22757365 726e616d 65223a22 67757074 61222c22 75736572 656d6169 6c223a22 66686a6a 6473227d 2c226d65 73736167 65223a22 4c6f6769 6e205375 63636573 7366756c 6c79227d> success={"code":0,"userinfo":{"id":"172","firstname":"Ay","lastname":"ta","username":"ss","useremail":"email"},"message":"Login Successfully"}

但是无法从响应对象中提取数据。发生崩溃

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSInlineData objectForKey:]: unrecognized selector sent to instance 0x7e351cc0'

1 个答案:

答案 0 :(得分:4)

删除显示

的行
manager.responseSerializer=[AFHTTPResponseSerializer serializer];

默认情况下,AFNetworking会为您解析您的JSON。 AFHTTPResponseSerializer将只为您提供一个NSData对象作为responseObject