Pergunta

I am using ASIHTTPRequest to get JSON response from server. And I want to convert this response to NSArray. My code:

    NSURL *url = [NSURL URLWithString:@"http://chirkov.net.ua/iosnettest/request.php?act=showdata&query=2;0;3;0;ASC"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error) { 
    NSData *responseData = [[NSMutableData alloc] initWithData:[request responseData]];
    NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:responseData];
    NSLog(@"array = %@",array);
}

But got exception Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0xffffffef, 0xffffffbb, 0xffffffbf, 0x5b, 0x7b, 0x22, 0x69, 0x64. How can I solve my problem?

Foi útil?

Solução

You getting JSON data so you have to convert that data using NSJSONSerialization. Have a look at class reference.

http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html

Also check this Working with JSON

Outras dicas

You can use NSJSONSerialization like this:

NSError *jsonError = nil;
NSArray *jsonObject = (NSArray *)[NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&jsonError];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top