iOS5에서 sbjson까지 특수 문자를 웹 서비스로 보내는 데 문제가 있습니다.Xcode/ios5 ~ SBJso의 특수 문자
json 문자열을 특수 문자없이 보내려고했지만 아무 문제없이 통과했습니다. 그러나 "æøå"또는 "é"와 같은 특수 문자를 입력하자마자 위의 오류가 발생합니다.
여기 json과 iOS에 대한 많은 답변을 살펴 보았지만 대개 답변은 웹 서비스의 URL 문자열에있는 특수 문자에 대한 것입니다. 내가 뭘 결정할 수 있는지에 대해서도 전체 문자열은 SBJson을 통해 UTF-8로 인코딩됩니다.
동일한 문제가 있었고 이에 대한 해결책을 알고있는 사람은 누구입니까?
미리 감사드립니다.
이는 서버에 요청을 보낼 때 발생합니다.
요청을 보낼 때 사용하는 코드입니다.
-(void) execMethod:(NSString*)methodName andParams:(NSArray*)parameters withID:(NSString*)identificator {
//RPC
NSMutableDictionary* reqDict = [NSMutableDictionary dictionary];
[reqDict setObject:methodName forKey:@"method"];
[reqDict setObject:parameters forKey:@"params"];
[reqDict setObject:identificator forKey:@"id"];
//RPC JSON
NSString* reqString = [NSString stringWithString:[reqDict JSONRepresentation]];
//Request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSData* requestData = [NSData dataWithBytes:[reqString UTF8String] length:[reqString length]];
//prepare http body
[request setHTTPMethod: @"POST"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
if (urlConnection != nil) {
[urlConnection release];
urlConnection = nil;
}
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
[request release];
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
}
스택 추적 :
0 xRapp 0x00015925 -[JSONRPCService execMethod:andParams:withID:] + 1077
1 xRapp 0x00017eaa -[xRappSyncWSViewController syncServerUpdate:] + 2586
2 xRapp 0x000187a7 -[xRappSyncWSViewController data1Loaded:] + 2167
3 xRapp 0x000171d3 -[xRappSyncWSViewController dataLoaded:] + 627
4 xRapp 0x00015da8 -[JSONRPCService connectionDidFinishLoading:] + 200
5 Foundation 0x00eb8a59 ___NSURLConnectionDidFinishLoading_block_invoke_0 + 40
6 Foundation 0x00eb6e94 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke_0 + 40
7 Foundation 0x00eb7eb7 -[NSURLConnectionInternalConnection invokeForDelegate:] + 39
8 Foundation 0x00eb6e4f -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 201
9 Foundation 0x00eb6fd5 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76
10 Foundation 0x00dfbf6a _NSURLConnectionDidFinishLoading + 43
11 CFNetwork 0x01998bbd _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 241
12 CFNetwork 0x01a655ea _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 584
13 CFNetwork 0x0198f298 _ZN19URLConnectionClient13processEventsEv + 174
14 CFNetwork 0x01a6516b _ZThn52_N25URLConnectionInstanceData24multiplexerClientPerformEv + 21
15 CFNetwork 0x0198f137 _ZN17MultiplexerSource7performEv + 259
16 CoreFoundation 0x0120b97f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
17 CoreFoundation 0x0116eb73 __CFRunLoopDoSources0 + 243
18 CoreFoundation 0x0116e454 __CFRunLoopRun + 1012
19 CoreFoundation 0x0116ddb4 CFRunLoopRunSpecific + 212
20 CoreFoundation 0x0116dccb CFRunLoopRunInMode + 123
21 GraphicsServices 0x01eef879 GSEventRunModal + 207
22 GraphicsServices 0x01eef93e GSEventRun + 114
23 UIKit 0x004c3a9b UIApplicationMain + 1175
24 xRapp 0x000021f8 main + 152
25 xRapp 0x00002155 start + 53
오류의 스택 추적과 Json 데이터를 생성하여 관련 질문에 보내는 관련 코드를 추가 할 수 있습니까? 요청을 보내거나 응답을받을 때 오류가 발생합니까? – Codo
요청하신 정보가 추가되었습니다. :) – pvaskeli