Tôi đang cố chuyển đổi một từ điển NSD thành XML. (Tôi đã thành công trong việc chuyển đổi NSDictionary thành JSON). Nhưng bây giờ tôi cần phải chuyển đổi NSDictionary thành XML. Có serializer tích hợp trong Objective-C như là một cho JSON?NSDictionary to XML
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"];
... // đang không liên quan khác bỏ qua
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]);
Các NSLog không in một chuỗi định dạng XML. Nó in nó giống như một NSDictionary. Tôi nên sử dụng gì để sắp xếp thứ tự từ điển NSD sang XML?
Bạn nên chuyển đổi bằng tay. – Nekto
Tôi cho rằng có một cách dễ dàng hơn? vì mục tiêu-c có một bộ nối tiếp tích hợp sẵn cho JSON. – acecapades