get values of particular key in nsdictionary

前端 未结 3 2020
醉话见心
醉话见心 2020-12-24 07:55

I saved the json parsing result in a dictionary which look like:

{
 \"statusCode\":\"200\",
\"body\":[
  {
     \"status\":\"succes         


        
相关标签:
3条回答
  • 2020-12-24 08:11

    Following will give you the desired object

    NSDictionary *dict=[results valueForKeyPath:@"data.abcd"][0];
    

    For individual:

    NSString *categoryString=[[results valueForKeyPath:@"data.abcd"][0] objectForKey:@"Category"];
    NSString *idString=[[results valueForKeyPath:@"data.abcd"][0] objectForKey:@"id"];
    NSString *titleString=[[results valueForKeyPath:@"data.abcd"][0] objectForKey:@"title"];
    

    Also,

    NSString *categoryString=dict[@"Category"];
    NSString *idString=dict[@"id"];
    NSString *titleString=dict[@"title"];
    
    0 讨论(0)
  • 2020-12-24 08:19

    That is an array so use objectAtIndex: (i.e. [getcat objectAtIndex:0] or getcat[0])

    0 讨论(0)
  • 2020-12-24 08:20

    Check like this:

    NSString *value=[[[getcate valueForKey:@"abcd"] objectAtIndex:0] valueForKey:@"category"];
    
    0 讨论(0)
提交回复
热议问题