What's the best way to convert a JavaScript array (saved in an NSString) with this format:
["Hello", "World"]
in an NSArray?
Thanks
What's the best way to convert a JavaScript array (saved in an NSString) with this format:
["Hello", "World"]
in an NSArray?
Thanks
Try this!
NSString * jsonString = @"[\"Hello\",\"World\"]";
NSError * serializationError = nil;
NSArray * array = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&serializationError];
NSLog(@"NSArray - %@ \n error - %@", array, serializationError.localizedDescription);
Log:
NSArray - ( Hello, World ) error - (null)
I can't tell exactly what your input string is, but you can use NSString's componentsSeparatedByString function to split up a string into an array of substrings.
NSJSONSerialization.