I am doing an authentication by using AFNetworking like below
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
// Parsing will be here
{
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"ERROR :jason is %@",JSON);
}];
[client enqueueHTTPRequestOperation:operation];
Below is a JSON which received from server
{
"first_name" = A;
"last_name" = B;
}
Question : How can a parse this JSON in ios. I am stuck because the return from server does not have any tag at all. If its format was
{
"user": {
"first_name": "A",
"last_name": "B",
}
}
I could parse by doing the following
NSArray *userList = [[NSArray alloc] init];
userList = [JSON objectForKey:@"results"];
Any ideas?
{ "X" : "Y" }is perfectly valid JSON (as is5).JSONis the parsed result of the JSON string and is, in both of the above cases, an NSDictionary.Postmanfrom Chrome and the result is returned like that.What I meant about tag is the name of the object. Therefore, in the second JSON, it isuser.I agree that I have not parsed because given aNSDictionary, I dont know how to turn it into an array... because it does not have a key ( like the second one has a key nameduserso that I can doobjectForKeyto return an array...