I’m new to JSON and web services so bear with me. I am getting back a response from a web server. In PostMan, it looks something like:
{
"Response": {
"TranscriptSource": "MD",
"Result": [
{
"Variant": {
"Chromosome": "chr1",
"Position": 13302,
"ReferenceAllele": "C",
"VariantAlleles": "T"
}
}
],
"JobId": 0
}
}
And if in my connectionDidFinishLoading method, I do this:
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:self.receivedData options:kNilOptions error:&error];
[dict enumerateKeysAndObjectsUsingBlock:^(id obj, id key, BOOL *stop) {
NSLog(@"key: %@ obj: %@\n", [key description], [obj description]);
}];
I get the same output. Basically I want what’s in that “Variant” field. So I thought I would start by doing
id result = [dict objectForKey@"Result"];
When I step through the debugger, result is nil. I wasn’t sure why since I can print it out.
In the end my main question is, how do I get access to the Variant part of the response, but if you know why id result would be nil, that would also be cool. Thanks!
Your top-level item is an object with a single key, “Response”. It looks like you want: