我正在开发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
我之前没有遇到过这种错误。我用谷歌搜索但未找到解决方案。
崩溃报告
答案 0 :(得分:-2)
我不确定它是否能正常工作,但在你的情况下,对象已经发布并且你试图访问它,所以我更喜欢这个解决方案,请试试这个。
SBJsonWriter * jsonWriter = [[SBJsonWriter new] retain];