Skip to content
Snippets Groups Projects
Commit 0d543126 authored by cramakri's avatar cramakri
Browse files

Fix crash in converting JSON string that included non-ASCII characters. Now assume UTF-8

SVN: 27458
parent de2e85bf
No related branches found
No related tags found
No related merge requests found
...@@ -25,11 +25,17 @@ ...@@ -25,11 +25,17 @@
#import "CISDOBIpadService.h" #import "CISDOBIpadService.h"
///! Convert a JSON string to objects. Returns nil if the string is nil. ///! Convert a JSON string to objects. Returns nil if the string is nil.
id ObjectFromJsonData(NSString *jsonData, NSError **error) id ObjectFromJsonData(NSString *jsonDataString, NSError **error)
{ {
if (nil == jsonData) return nil; if (nil == jsonDataString) return nil;
NSData *jsonData = [jsonDataString dataUsingEncoding: NSUTF8StringEncoding];
if (!jsonData) {
NSLog(@"Could not convert json string (%@) to UTF-8", jsonDataString);
// Do not treat this as an error -- just log it
return nil;
}
return [NSJSONSerialization JSONObjectWithData: [jsonData dataUsingEncoding: NSASCIIStringEncoding] options: 0 error: error]; return [NSJSONSerialization JSONObjectWithData: jsonData options: 0 error: error];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment