views:

60

answers:

1

Here is my code it looks ok
But it crash when running

NSString *urlAddress = [NSString stringWithFormat:@"http://www....php"]; 
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 
[request setURL:[NSURL URLWithString:urlAddress]]; 
[request setHTTPMethod:@"GET"]; 

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
NSLog(@"NSData is :%@",returnData);


NSArray *results = [[NSArray alloc] initWithDasta:returnData]; 
NSLog(@"NSArray is :%@",results);

I think that's an incompatible Object-C type initializing NSArray

A: 

Hi everyone first thanks for the answer I figure out this problem,I think I make things too complex here is my code ,I found I get the binary data,so I just need to translate the data into UTF-String than it become the source I can read

- (void)loadView {NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.someAddress.php"]
                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:60.0];
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];}

Than I put the data in my receivedData

  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSMutableData *receivedData = [[NSMutableData data] retain];

    [receivedData appendData:data];
NSLog(@"data is:%@",receivedData);
NSString *listFile = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding];   
    NSLog(@"listFile : %@",listFile);
NSArray *plist = [listFile propertyList];
    NSLog( @"plist count is %i", [plist count]);  
    NSLog( @"plist is %@", plist );
}

In The console debugger

You can see the "data" is a binary data and the "listFile" is a XML code last I got my plist format in "plist"

WebberLai
You're creating a new data object every time you receive data; you aren't appending every chunk to the same data object like you meant to. You need to make `receivedData` an instance variable, not a local variable, and create the data object in advance of receiving any data. Also, don't forget to release what you create or retain; see the Memory Management Programming Guide: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/
Peter Hosey