Last active
August 29, 2015 14:06
-
-
Save mhayashi/f23152624e89f495438e to your computer and use it in GitHub Desktop.
JSON to NSDictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSData *jsonData = [@"{}" dataUsingEncoding:NSUTF8StringEncoding]; // --> {}; | |
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:jsonData | |
options:NSJSONReadingAllowFragments | |
error:nil]; | |
jsonData = [@"{\"a\":{}}" dataUsingEncoding:NSUTF8StringEncoding]; // --> { a = {}; } | |
result = [NSJSONSerialization JSONObjectWithData:jsonData | |
options:NSJSONReadingAllowFragments | |
error:nil]; | |
jsonData = [@"{\"a\":false}" dataUsingEncoding:NSUTF8StringEncoding]; // --> { a = 0; } | |
result = [NSJSONSerialization JSONObjectWithData:jsonData | |
options:NSJSONReadingAllowFragments | |
error:nil]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
{}
is not falsey. We have to checkresult.count
if we want to know whether the dictionary is empty or not.