1

から位置データを取得しfoursquare api、このデータを に渡してwebserviceに挿入していdatabaseます。

たとえば、メキシコシティの位置データを取得すると、いくつかの特殊文字が含まれており、次のエラーが発生します:-

 Unrecognized escape sequence. (13443):

現在、JSON 解析に次のエンコーディングを使用しています:-

 NSString *requestString =  [jsonstring UTF8String];

JSONのÉspanolなどの特殊文字 (スペイン語データ)を解析するにはどうすればよいですか?

解決策はありますか?

ありがとう。

4

2 に答える 2

1

私もjsonで同じ問題を抱えていました。次のコードを使用して、この特殊文字の問題を解決しました:-

+(NSString *)http_post_method_changed:(NSString *)url content:(NSString *)jsonContent
{
NSURL *theURL = [NSURL URLWithString:url];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f];
NSData *requestData = [jsonContent dataUsingEncoding:NSUTF8StringEncoding];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[theRequest setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody: requestData];
NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *theResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
NSString *data=[[NSString alloc]initWithData:theResponseData encoding:NSUTF8StringEncoding];
NSLog(@"url to send request= %@",url);
NSLog(@"response1111:-%@",data);
return data;
}

送信する URL と json を渡すと、目的の応答が返されます。

于 2013-07-03T10:12:45.743 に答える
0

これを使いましたか?

NSArray *dataArray =
  [NSJSONSerialization JSONObjectWithData:_data
                                  options:NSJSONReadingAllowFragments
                                    error:&error];

フィードが実際に UTF-8 であることを (forsquare API ドキュメントを参照して) 確認してください。そうすれば、上記はエラーなしで機能するはずです。

これは、API フィードが配列を送信していることを前提としていますNSDictionary。それ以外の場合に使用してください。

于 2013-07-03T09:34:27.477 に答える