2011-12-26 6 views
2

iOS5からsbjsonまでの特殊文字をWebサービスに送信する際に問題があります。Xcode/ios5〜SBJsoの特殊文字

私は特殊文字なしでjson文字列を送信しようとしましたが、問題なくそのまま通過しました。しかし、私が "æøå"や "é"のような特殊文字を入力するとすぐに、私は上記のエラーを受け取ります。

ここではjsonとiOSで多くの回答を見てきましたが、ほとんどの回答はWebサービスの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 
+1

エラーのスタックトレースと、Jsonデータを作成して質問に送信する関連コードを追加してください。また、要求を送信したり、応答を受け取ったりするときにエラーが発生しますか? – Codo

+0

あなたが求めた情報を追加しました。 :) – pvaskeli

答えて

2

あなたのスタックトレースがちょうどsuspicousメソッドのスタックトレースではなく、発生したエラーのスタックトレースであると思われます。正確な位置を取得するためにブレークポイントを設定する方法については、Breaking on unrecognized selectorを参照してください。ブレークポイントで停止すると、より良い情報を持つスタックトレースが得られます。

NSData* requestData = [NSData dataWithBytes:[reqString UTF8String] length:[reqString length]]; 

このラインは(文字で測定された)文字列の長さをアップミックスし、UTF-8でエンコードされたバイナリデータの長さ(:

一の疑わしいコード内の行がある、と述べましたバイトで測定)。アクセント付きの文字のような特殊文字があれば、それらは異なっています。

より良い(短い)代替は次のとおりです。

NSData* requestData = [reqString dataUsingEncoding:NSUTF8StringEncoding]; 

それは解決策ではない場合は、改善されたスタックトレースを追加してください。

+0

これは素晴らしい仕事。ご協力いただきありがとうございます。 – pvaskeli