Convert nsdictionary to nsdata

后端 未结 5 2100
伪装坚强ぢ
伪装坚强ぢ 2021-02-05 19:38

have an app that can take a picture and then upload to a server. encoding it to base 64 and pass it thru a XMLRPC to my php server.

i want to take the NSDictionary info

5条回答
  •  青春惊慌失措
    2021-02-05 20:28

    The NSPropertyListSerialization class give you the most control over writing and reading of property lists:

    NSDictionary *dictionary = @{@"Hello" : @"World"};
    NSData *data = [NSPropertyListSerialization dataWithPropertyList:dictionary
                                                format:NSPropertyListBinaryFormat_v1_0
                                                options:0
                                                error:NULL];
    

    Read:

    NSData *data = ...
    NSPropertyListFormat *format;
    NSDictionary *dictionary = [NSPropertyListSerialization propertyListWithData:data
                                                            options:0
                                                            format:&format
                                                            error:NULL];
    

提交回复
热议问题