[英]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. 我有一个NSMutableDictionary,我想将其作为XML文件发送到URL。 I want the XML file to be stored in a folder on the URL. 我希望将XML文件存储在URL上的文件夹中。
I have found through googling stuff that I can "serealize" the NSMutableDictionary. 通过谷歌搜索,我发现我可以“重新实现” 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? 我是否必须将此识别的对象发送到URL,还是可以将该识别的对象转换为XML文件,然后将该XML文件发送到URL?
Right now I donot have a PHP script on the server that can parse the XML file. 现在,我在服务器上没有可以解析XML文件的PHP脚本。 But I just want the XML file to reside on the URL. 但是我只希望XML文件驻留在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? 我可以使用NSURLConnection POST方法来执行此操作,还是必须使用其他方式(例如ftp)? Thanks 谢谢
I would convert the NSDictionary
to json using: 我将使用以下命令将NSDictionary
转换为json:
And then I would send the json to your webserver using: 然后我将使用以下命令将json发送到您的网络服务器:
It would be much easier on both ends to deal with json. 在两端处理json会容易得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.