2

我正在开发 iOS 应用程序。在一种情况下,我正在像这样向服务器发送电话号码和一些短信

- (void)postData:(NSString *)message :(NSString *)mobileno
{

NSLog(@"postData is called");
@try
{
    NSString *urlString = [NSString stringWithFormat:@"http://anlgelist.commonshell.net/api/account"];
    NSURL *url = [[NSURL alloc] initWithString:urlString];
    NSMutableURLRequest *urlRequest1=[NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    NSMutableDictionary *postDictionary=[[NSMutableDictionary alloc]init];
  [postDictionary setValue:message forKey:@"Message"];
  [postDictionary setValue:mobileno forKey:@"MobileNumber"];
      SBJsonWriter *jsonWriter = [SBJsonWriter new];
   NSError *error = nil;
    NSLog(@"~~~~~~~~ postDictionary is %@",postDictionary);

    NSString * jsonDataString =[jsonWriter stringWithObject:postDictionary];

    if ( ! jsonDataString )
    {
        NSLog(@"Error: %@", error);
    }

    NSData *requestData = [NSData dataWithBytes:[jsonDataString UTF8String] length:[jsonDataString length]];
    [urlRequest1 setHTTPMethod:@"PUT"];
    [urlRequest1 setValue:@"application/json" forHTTPHeaderField:@"content-type"];
    [urlRequest1 setHTTPBody: requestData];
    connection1 = [NSURLConnection connectionWithRequest:urlRequest1 delegate:self];

}
@catch (NSException *exception)
{
    ////NSLog(@"exception is %@",exception);

    @throw exception;
}

}

我不断调用此 Web 服务来发送详细信息。但有时我收到以下错误并且应用程序崩溃。

<Error>: -[__NSCFDictionary _expandedCFCharacterSet]: unrecognized selector sent to instance 0x14fdf350

我以前没有遇到过这种错误。我用谷歌搜索但没有找到解决方案。

崩溃报告现为

在此处输入图像描述

4

1 回答 1

-2

我不确定它会正常工作,但在你的情况下,对象已经释放并且你尝试访问它,所以我更喜欢这个解决方案,请试试这个。

SBJsonWriter *jsonWriter = [[SBJsonWriter new]retain];

于 2014-02-27T11:57:01.717 回答