Converting NSString to NSDictionary / JSON

前端 未结 5 1592
时光说笑
时光说笑 2020-12-02 07:05

I have the following data saved as an NSString :

 {
    Key = ID;
    Value =         {
        Content = 268;
        Type = Text;
    };
},
          


        
5条回答
  •  Happy的楠姐
    2020-12-02 07:27

    I think you get the array from response so you have to assign response to array.

    NSError *err = nil;
    NSArray *array = [NSJSONSerialization JSONObjectWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&err];
    NSDictionary *dictionary = [array objectAtIndex:0];
    NSString *test = [dictionary objectForKey:@"ID"];
    NSLog(@"Test is %@",test);

提交回复
热议问题