Get values from NSDictionary

前端 未结 3 1421
后悔当初
后悔当初 2021-01-22 13:43

Hi I\'m new to iOS development. I want to get response and add those values to variable.

I tried it but I\'m getting below response. I don\'t understand why there is sla

3条回答
  •  悲哀的现实
    2021-01-22 14:14

    First you need to parse your string.

    NSString *aString = @"[{\"VisitorID\":\"2864983a-e26b-441a-aedf-84e2a1770b8e\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kanasalingam\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]},{\"VisitorID\":\"133bc108-b3bf-468a-9397-e1b0dba449db\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kumar\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]}]";
    
    NSData *data = [aString dataUsingEncoding:NSUTF8StringEncoding];
    id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    NSLog(@"%@",[[json objectAtIndex:0] objectForKey:@"VisitorID"]);
    

提交回复
热议问题