2013-02-13 76 views
0

我正在爲ios開發預約應用程序。我使用.net Web服務從數據庫獲取數據。我在Android和Windows Phone應用程序中使用它,但是我無法使用ios。它返回具有子對象列表的子對象列表。從iOS上的.net Web服務獲取對象列表

例如,FirmaGetir方法有一個參數:firID(字符串)。我如何將參數傳遞給Web服務?我如何解析這些項​​目? 我需要一個示例代碼。感謝您的關注。

Web服務請求

POST /webservice1.asmx HTTP/1.1 
Host: example.com 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <FirmaGetir xmlns="http://tempuri.org/"> 
     <firID>string</firID> 
    </FirmaGetir> 
    </soap12:Body> 
</soap12:Envelope> 

Web服務的結果

HTTP/1.1 200 OK 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <FirmaGetirResponse xmlns="http://tempuri.org/"> 
     <FirmaGetirResult> 
     <Firma> 
      <firma_adi>string</firma_adi> 
      <adres>string</adres> 
      <telefon>string</telefon> 
      <id>string</id> 
      <sektor>string</sektor> 
      <alt_sektor>string</alt_sektor> 
      <alt_sektor_adi>string</alt_sektor_adi> 
      <servis>string</servis> 
      <map>string</map> 
      <slogan>string</slogan> 
      <sayfaGosterimi>int</sayfaGosterimi> 
      <gpsilce>string</gpsilce> 
      <gpssemt>string</gpssemt> 
      <gpspk>string</gpspk> 
      <duyuru> 
      <baslik>string</baslik> 
      <icerik>string</icerik> 
      <link>string</link> 
      <image>string</image> 
      </duyuru> 
      <firma_link> 
      <tam_adi>string</tam_adi> 
      <kisa_adi>string</kisa_adi> 
      <firma_link>string</firma_link> 
      </firma_link> 
     </Firma> 
     </FirmaGetirResult> 
    </FirmaGetirResponse> 
    </soap12:Body> 
</soap12:Envelope> 
+0

使用NSXmlparser提供的蘋果來解析這個xml – Vinodh 2013-02-13 10:33:00

+0

我知道我用什麼,但怎麼樣?我該如何解析這種類型的XML? – 2013-02-13 11:41:27

回答

0

使用touchXml文件導出到您的項目

和修改基於以下方法您的要求

- (NSArray *) parseAllShopInfoResponse:(NSString *)AllShopInfoResponse 
{ 


    NSMutableArray *allShopInfoDTOArray = [[NSMutableArray alloc]init]; 


    CXMLDocument *inventoryResponseObject = [[CXMLDocument alloc] initWithXMLString:AllShopInfoResponse options:0 error:nil]; 

    NSArray *resultNodes = [inventoryResponseObject nodesForXPath:@"//shopsListDTO" error:nil]; 

// NSLog(@"ShopsList nodes: %@", resultNodes); 

    for (CXMLElement *resultElement in resultNodes) 
    { 
     NSMutableDictionary *allShopInfo = [[NSMutableDictionary alloc] init]; 

     for(int counter = 0; counter < [resultElement childCount]; counter++) 
     { 

      if ([[resultElement childAtIndex:counter] stringValue] == nil) 
      { 
       [allShopInfo setObject:@" " forKey:[[resultElement childAtIndex: counter] name]]; 
      } 
      else 
      { 
       [allShopInfo setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]]; 
      } 

//   NSLog(@"ShopsList DIC %@",allShopInfo); 

     } 
     [allShopInfoDTOArray addObject:[allShopInfo copy]]; 


    } 


    return [self returnAllShopInfoObjects:allShopInfoDTOArray]; 

} 


- (NSArray*) returnAllShopInfoObjects: (NSArray *)allShopInfoArray 
{ 

    NSMutableArray *allShopInfoObjects=[[NSMutableArray alloc]init]; 

    for (NSDictionary *allShopInfoDictionary in allShopInfoArray) 
    { 

//  NSLog(@"ALL Shop Info Dictionary .....%@",allShopInfoDictionary); 

     allShopInfoObject = [[ShopBasicDetails alloc]init]; 

     allShopInfoObject.shopId = [[allShopInfoDictionary objectForKey:@"shopId"] intValue]; 
     allShopInfoObject.shopName = [allShopInfoDictionary objectForKey:@"shopName"]; 
     allShopInfoObject.onlineStatus = [[allShopInfoDictionary objectForKey:@"onlineStatus"]intValue]; 
     allShopInfoObject.shopDetailsDownloadTime = (NSDate *)[allShopInfoDictionary objectForKey:@"dateTime"]; 
     allShopInfoObject.shopLatitudeValue = [[allShopInfoDictionary objectForKey:@"latitude"]doubleValue]; 
     allShopInfoObject.shopLongitudeValue = [[allShopInfoDictionary objectForKey:@"longitude"]doubleValue]; 
     NSURL *thunmbnailImageUrl = [NSURL URLWithString: [allShopInfoDictionary objectForKey:@"logoThumbnailUrl"]]; 
     UIImage *thunmbnailImage = [UIImage imageWithData: [NSData dataWithContentsOfURL:thunmbnailImageUrl]]; 

     allShopInfoObject.thumbnailImage = thunmbnailImage; 
     CLLocation *shopLocation = [[CLLocation alloc] initWithLatitude:allShopInfoObject.shopLatitudeValue longitude:allShopInfoObject.shopLongitudeValue]; 

//  NSLog(@"Distance i meters: %f", [userCurrentPosition getDistanceFrom:shopLocation]); 
     allShopInfoObject.distance = [userCurrentPosition getDistanceFrom:shopLocation]/1000; 

     [allShopInfoObjects addObject:allShopInfoObject]; 



    } 
// NSLog(@"OBJECTS : %@",allShopInfoObjects); 
    [outputDelegate ParserOutputDelegate:allShopInfoObjects]; 

    return allShopInfoObjects; 
} 
相關問題