2012-03-09 20 views
0

こんにちはすべての配列の合計応答を取得するためのコードは実際に私はここで私の問題は、次のクラスでメソッドを呼び出すときに私は配列の応答をnullになっているiPhoneでこの問題を避けてください。応答データを配列に取得する方法は?

私のコードは次のとおり

- (ボイド)countrySelection {

NSString *jobSearchUrlString = [NSString stringWithFormat:@"http://infra2appsmobile.cloudapp.net/Infra2Apps.svc/Countries"]; 
    //NSLog(@"url for new articles is = %@",jobSearchUrlString); 
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:jobSearchUrlString]]; 

    NSURLConnection *theconnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
    if (theconnection) { 
     RoutData = [[NSMutableData alloc] init]; 
    } 

} 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 

    [RoutData setLength: 0]; 
} 
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [RoutData appendData:data]; 

      NSString *thexml = [[NSString alloc] initWithData:RoutData encoding:NSUTF8StringEncoding]; 

    NSDictionary *dictXML= [XMLReader dictionaryForXMLString:thexml error:nil]; 

    NSMutableArray *arrStation = [[dictXML objectForKey:@"feed"] objectForKey:@"entry"] ;//this would return the array of station dictionaries 

    for (int i=0; i<[arrStation count]; i++) { 
     NSLog(@"---->> String Type Country names <<---: %@",[[[[[arrStation objectAtIndex:i] objectForKey:@"content"] objectForKey:@"m:properties"] objectForKey:@"d:CountryName"] objectForKey:@"text"]); 
     [materialarray addObject:[[[[[arrStation objectAtIndex:i] objectForKey:@"content"] objectForKey:@"m:properties"] objectForKey:@"d:CountryName"] objectForKey:@"text"]]; 

     NSLog(@"--->>** Array Type Country names **<<<---%@",materialarray); 


    } 



} 

私の応答がある:

2012-03-09 12:49:40.856 TABLESAMPLE [4862:F803] - --- >>文字列型国名< < --- フランス 2012-03-09 12:49:40.867 TableSample [4862:f803] --- >> **配列タイプ国名< < < ---(null) 2012-03-09 12:49:40.868 TableSample [4862:f803] ---- >>文字列型国名< < ---: MEA HQ 2012-03-09 12:49:40.869テーブルサンプル[4862:f803] --- >>アレイタイプ国名< < < ---(ヌル) 2012-03-09 12:49:40.870 TableSample [4862:f803] - - >>文字列タイプ国名< < ---: イスラエル 2012-03-09 12:49:40.871 TABLESAMPLE [4862:F803] --- >>アレイタイプ国名< < < --- (ヌル) 2012-03-09 12:49:40.872 TableSample [4862:f803] ---- >>文字列型国名< < ---: トルコ 2012-03-09 12:49:40.879 TableSample [4862: f803] --- >>配列タイプ国名< < < ---(null) 2012-03-09 12:49:40.879 TableSample [4862:f803] ---- >>文字列型国名< < ---: UAE 2012-03-09 12:49:40.880 TABLESAMPLE [4862:F803] --- >>アレイタイプ国名< < < ---(ヌル) 2012-03-09 12:49:40.881 TableSample [4862:f803] ---- >>文字列型の国名< < ---: SA 2012-03-09 12:49:40.881 TABLESAMPLE [4862:F803] --- >>アレイタイプ国名< < < ---(ヌル) 2012-03-09 12:49:40.882 TableSample [4862:f803] ---- >>文字列型国名< < --- RSA 2012-03-09 12:49:41.020 TableSample [4862:f803 ] --- >>アレイタイプの国名< < < ---(ヌル) 2012-03-09 12:49:41.021 TABLESAMPLE [4862:F803] ---- >>文字列タイプ国名< < ---: WE HQ 2012-03-09 12:49:41.022 TABLESAMPLE [4862:F803] --- >>アレイタイプ国名** < < < ---(にヌル

+0

私は答えを知っていますが、私はあなたに答えを与えるのが好きではありません!!!! :) –

答えて

2

connectionDidFinishLoadingデリゲートメソッド応答文字列を取得するには、その応答文字列にJSONValueを呼び出す必要があります。結果は配列に渡されます。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
    [connection release]; 
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
    NSLog(@"responseString %@",responseString); 
    self.responseData = nil; 
    NSArray *responseArray = [responseString JSONValue]; 
    [responseString release]; 
} 
+0

申し訳ありませんが、私のアプリケーションで動作していない友人becozは、基本的には、XML解析です。 – laxmanperamalla

+0

JSONパーサーデリゲートメソッドを実装しています。 XML解析を使用している場合は、NSXMLParserデリゲートメソッドを実装する必要があります。ここにリンクがあります:https://developer.apple.com/library/ios/#documentation/cocoa/reference/NSXMLParserDelegate_Protocol/Reference/Reference.html – Dee

1

materialarrayが割り当てられていることを確認してください。

問題があると思います。

これが役に立ちます。

関連する問題