从NSDictionary能转换到xml(其实是apple的plist)格式数据!哈哈,以后保存数据又多了种方式。
输出结果为:
代码如下:
NSDictionary *dictionary = @{@"name": @"huangxinping", @"id": @"35"};
NSString *error;
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dictionary format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
NSLog(@"%@",[[NSString alloc] initWithData:plistData encoding:NSUTF8StringEncoding]);
输出结果为:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>id</key>
<string>35</string>
<key>name</key>
<string>huangxinping</string>
</dict>
</plist>