2011-06-19 24 views
0

我有一個NSMutableDictionary,我想將它作爲XML文件發送到URL。我希望XML文件存儲在URL的文件夾中。我想發送一個NSMutableDictionary從iPhone到服務器

我發現通過Google搜索可以「實現」NSMutableDictionary。下面是我做到的:

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]; 

這個「serealizes」字典。是否必須將此實現的對象發送到URL,或者可以將此實現的對象轉換爲XML文件,然後將該XML文件發送到URL?

現在我沒有可以解析XML文件的服務器上的PHP腳本。但我只想讓XML文件駐留在URL上。 我可以這樣做嗎? 我可以使用NSURLConnection POST方法來做到這一點,否則我將不得不使用其他方式如ftp? 感謝

回答

0

我會轉換NSDictionary使用到JSON:

json-framework

然後,我會使用JSON發送到Web服務器:

AsiHttpRequest

這會容易得多在兩端處理json。

+0

感謝您的回答。不過,我現在更喜歡XML,因爲我對json並不熟悉。 – banditKing

+0

有人可以幫助我解決上述問題。如何將我的字典轉換爲可發送到URL的XML文件? – banditKing

+0

好吧,我個人認爲你通過避免json犯了一個錯誤,xml is * hardder *。試試這個xml的android教程: http://www.ibm.com/developerworks/opensource/library/x-android/ – nickfox

相關問題