开发者

I want to send a NSMutableDictionary from the iPhone to a server

I have a NSMutableDictionary and I want to send it to a URL as an XML file. I want the XML file to be stored in a folder on the URL.

I have found through googling stuff that I can "serealize" the NSMutableDictionary. Here is how I did it:

NSString *error;
self.rootSerialDict = [[NSMutableDictionary alloc] initWithCapacity:5];

[self convertDrinkArrayToDictionary];
[self.rootSerialDict setObject:self.drinkSerialDic forKey:@"Drinks"];
[self convertSpecialsArrayToDictionary];
[self.rootSerialDict setObject:self.specialsSerialDic forKey:@"Specials"];  
[self convertCustomerInfoToDictionary];
[self.rootSerialDict setObject:self.customerInfoSerialDict forKey:@"CustomerInfo"];
[self convertLocationInfoToDictionary];
[self.rootSerialDict setObject:self.locationInfoSerialDict forKey:@"Location"];
[self createDictionaryOfMiscItems];
[self.rootSerialDict setObject:self.miscItemSerialDict forKey:@"MiscTotals"];

//convert the root serial dictionary to a XML plist
id plist = [NSPropertyListSerialization 
dataFromPropertyList:(id)self.rootSerialDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];

This "serealizes" the dictionary. Do I have to send this serealized object to the URL or can I convert this serealized object into an XML file and then send that XML file to the URL?

Right now I donot have a PHP script on the server that can parse the XML file. But I j开发者_JAVA技巧ust want the XML file to reside on the URL. Can I do this? Can I use the NSURLConnection POST method to do that or will I have to use some other way like ftp? Thanks


I would convert the NSDictionary to json using:

json-framework

And then I would send the json to your webserver using:

AsiHttpRequest

It would be much easier on both ends to deal with json.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜