Converting NSString to NSDictionary / JSON

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

I have the following data saved as an NSString :

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


        
5条回答
  •  情歌与酒
    2020-12-02 07:29

    Use this code where str is your JSON string:

    NSError *err = nil;
    NSArray *arr = 
     [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] 
                                     options:NSJSONReadingMutableContainers 
                                       error:&err];
    // access the dictionaries
    NSMutableDictionary *dict = arr[0];
    for (NSMutableDictionary *dictionary in arr) {
      // do something using dictionary
    }
    

提交回复
热议问题