Parse Plist (NSString) into NSDictionary

前端 未结 3 473
灰色年华
灰色年华 2020-11-27 15:52

So I have a plist structured string, that get dynamically (not from the file system). How would I convert this string to a NSDictionary.

I\'ve tried converting it N

3条回答
  •  天命终不由人
    2020-11-27 16:12

    See Serializing a Property List

    NSData* plistData = [source dataUsingEncoding:NSUTF8StringEncoding];
    NSString *error;
    NSPropertyListFormat format;
    NSDictionary* plist = [NSPropertyListSerialization propertyListWithData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error];
    NSLog( @"plist is %@", plist );
    if(!plist){
        NSLog(@"Error: %@",error);
        [error release];
    }
    

提交回复
热议问题