當我連接到Web服務,返回JSON字符串返回他們像XML:如何連接web服務並獲取json數據?
2014-02-07 00:17:15.673 Test[791:70b] <\?xml version="1.0" encoding="utf-8"?>
<\string xmlns="MBSCafe.Service.ServiceManager">{"query": [{"ID": "01","Name": "food"}]}<\/string>
相反,我想這一點:
{"query": [{"ID": "01","Name": "food"}]}
這是我的部分代碼:
NSString *urlString = @"http://mbsserver/MBSCafeService/ServiceManager.asmx/GetItemTypeList";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Accept"];
NSString *myRequestString = @"id="; // Attention HERE!!!!
myRequestString = [myRequestString stringByAppendingString:@"01"];
NSData *requestData = [NSData dataWithBytes:[myRequestString UTF8String] length:[myRequestString length]];
[request setHTTPBody: requestData];
它有什麼問題?
您檢查WebService的JSON響應,如果無論如何,如果這是不可能的,然後調用Web服務並將XML轉換爲JSON與[XMLReader](http://troybrant.net/blog/2010/09/simple-xml-到的NSDictionary轉換器/)。 – cjd