I am using the yajl_JSON library to create an NSDictionary from a JSON response for the bit.ly url shortening service.
JSON answer:
{
errorCode = 0;
errorMessage = "";
results = {
"http://www.example.com/" = {
hash = 4H5keM;
shortKeywordUrl = "";
shortUrl = "http://bit.ly/4BN4qV";
userHash = 4BN4qV;
};
};
statusCode = OK;
}
To clarify, http://example.com βis not a child of theβ result. "And when I figure it out, I have 3 three nested NSDictionaries.
The problem is that " http://example.com " is an arbitrary key. I want to access key data without knowing the key. In particular, therefore, I can get the value for "shortUrl". How can this be done effectively? Is there a way to make keyPath this way:
"results.*.shortUrl"
I accomplished this by doing the following, but I believe that this is not how it is done:
NSDictionary *jsonResponce = [data yajl_JSON];
NSString *missingKey = [[[jsonResponce valueForKeyPath:@"results"] allKeys] objectAtIndex:0];
NSLog(@"It is : %@", [[[jsonResponce objectForKey:@"results"] valueForKeyPath:missingKey] objectForKey:@"shortUrl"]);
XML, , , json/ objective-c.
, "example.com" , Bit.ly, ... ...
.