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?
试试这个:
NSLog(@"XML: %@",[[[Nsstring alloc] initWithData:theBodyData enCoding:NSUTF8StringEnCoding] autorelease]);总结
以上是内存溢出为你收集整理的iphone – NSDictionary到XML全部内容,希望文章能够帮你解决iphone – NSDictionary到XML所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)