0

hi all how is the code for get the total response in the array actually i have implemented code as shown in the below here my problem is when i calling the method in in next class i am getting array response null so plz help me to avoid this problem in iphone.

My code is:

-(void)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);


    }



}

My response is:

2012-03-09 12:49:40.856 TableSample[4862:f803] ---->> String Type Country names <<---: France 2012-03-09 12:49:40.867 TableSample[4862:f803] --->>** Array Type Country names <<<---(null) 2012-03-09 12:49:40.868 TableSample[4862:f803] ---->> String Type Country names <<---: MEA HQ 2012-03-09 12:49:40.869 TableSample[4862:f803] --->> Array Type Country names <<<---(null) 2012-03-09 12:49:40.870 TableSample[4862:f803] ---->> String Type Country names <<---: Israel 2012-03-09 12:49:40.871 TableSample[4862:f803] --->> Array Type Country names <<<---(null) 2012-03-09 12:49:40.872 TableSample[4862:f803] ---->> String Type Country names <<---: Turkey 2012-03-09 12:49:40.879 TableSample[4862:f803] --->> Array Type Country names <<<---(null) 2012-03-09 12:49:40.879 TableSample[4862:f803] ---->> String Type Country names <<---: UAE 2012-03-09 12:49:40.880 TableSample[4862:f803] --->> Array Type Country names <<<---(null) 2012-03-09 12:49:40.881 TableSample[4862:f803] ---->> String Type Country names <<---: SA 2012-03-09 12:49:40.881 TableSample[4862:f803] --->> Array Type Country names <<<---(null) 2012-03-09 12:49:40.882 TableSample[4862:f803] ---->> String Type Country names <<---: RSA 2012-03-09 12:49:41.020 TableSample[4862:f803] --->> Array Type Country names <<<---(null) 2012-03-09 12:49:41.021 TableSample[4862:f803] ---->> String Type Country names <<---: WE HQ 2012-03-09 12:49:41.022 TableSample[4862:f803] --->> Array Type Country names **<<<---(null

1
  • i know answer but i don't like to give an answer to u !!!! :) Commented Mar 9, 2012 at 7:31

2 Answers 2

2

In connectionDidFinishLoading delegate method you will get the response string, you need to call JSONValue on that response string it will give you the results in an array.

- (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];
}
Sign up to request clarification or add additional context in comments.

2 Comments

sorry friend it is not working in my application becoz basically it is xml parsing. give me another ans for me
You are implementing JSON parser delegate methods. If you are using XML parsing you need implement NSXMLParser delegate methods. Here is the link for it: developer.apple.com/library/ios/#documentation/cocoa/reference/…
1

Please make sure that materialarray is allocated.

I think there is where the problem is.

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.