Set text encoding for -responseString to UTF-8 by default, in case an encoding is not set in the response
This commit is contained in:
parent
8da80668f4
commit
4a93904566
2 changed files with 6 additions and 2 deletions
|
|
@ -128,7 +128,7 @@ extern NSString * const AFNetworkingOperationDidFinishNotification;
|
|||
/**
|
||||
The string representation of the response data.
|
||||
|
||||
@discussion This method uses the string encoding of the response to construct a string from the response data.
|
||||
@discussion This method uses the string encoding of the response, or if UTF-8 if not specified, to construct a string from the response data.
|
||||
*/
|
||||
@property (readonly, nonatomic, copy) NSString *responseString;
|
||||
|
||||
|
|
|
|||
|
|
@ -233,7 +233,11 @@ static inline NSString * AFKeyPathFromOperationState(AFOperationState state) {
|
|||
|
||||
- (NSString *)responseString {
|
||||
if (!_responseString && self.response && self.responseData) {
|
||||
NSStringEncoding textEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)self.response.textEncodingName));
|
||||
NSStringEncoding textEncoding = NSUTF8StringEncoding;
|
||||
if (self.response.textEncodingName) {
|
||||
textEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)self.response.textEncodingName));
|
||||
}
|
||||
|
||||
self.responseString = [[[NSString alloc] initWithData:self.responseData encoding:textEncoding] autorelease];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue