我正在尝试将NSDictionary转换为XML。(我已经成功地将NSDictionary转换为JSON)。但现在我需要将NSDictionary转换为XML。Objective-C中是否有像JSON那样的内置序列化器?
int r = arc4random() % 999999999;
//simulate my NSDictionary (to be turned into xml)
NSString *name = [NSString stringWithFormat:@"Posted using iPhone_%d", r];
NSString *stock_no = [NSString stringWithFormat:@"2342_%d", r];
NSString *retail_price = @"12345";
NSArray *keys = [NSArray arrayWithObjects:@"name", @"stock_no", @"retail_price", nil];
NSArray *objects = [NSArray arrayWithObjects:name,stock_no,retail_price, nil];
NSDictionary *theRequestDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSDictionary *theFinalRequestDictionary = [NSDictionary dictionaryWithObject:theRequestDictionary forKey:@"product"];
抱歉,我无法处理您的请求。 我们的服务目前仅支持英语到其他语言的翻译。
NSData *theBodyData = [NSPropertyListSerialization dataFromPropertyList:theFinalRequestDictionary format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];
NSPropertyListFormat format;
id XMLed = [NSPropertyListSerialization propertyListFromData:theBodyData
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:nil];
NSLog(@"the XMLed is this: %@", [NSString stringWithFormat:@"%@", XMLed]);
NSLog不能以XML格式打印字符串,它会像一个NSDictionary一样打印。那我应该使用什么来将我的NSDictionary序列化为XML呢?