Domanda

Sto usando una classe Singleton per recuperare JSON da un server remoto (tramite NsurlConnection) - tutto il seme per andare bene tranne quando cerco di analizzare il JSON usando JSONKIT.

Ecco alcuni codice

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

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"Connection failed! Error - %@ %@",
      [error localizedDescription],
      [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse   *)response
{
NSHTTPURLResponse *realResponse = (NSHTTPURLResponse *)response;
if (realResponse.statusCode == 200)
{
    apiData = [[NSMutableData alloc] init];
} else {
    NSLog(@"Bad response = %i",realResponse.statusCode);
}
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *jsonData = [[NSString alloc] initWithData:apiData encoding:NSUTF8StringEncoding];
NSDictionary *deserializedData = [jsonData objectFromJSONString];
[self.delegate dataLoaded:deserializedData]; 
}
.

L'errore che ottengo è in questa riga

 NSDictionary *deserializedData = [jsonData objectFromJSONString];

-[__NSCFString objectFromJSONString]: unrecognized selector sent to instance 0x7fc1cd0
.

Qualche idea cosa sta succedendo qui?Questo sembra essere il modo normale per analizzare JSON usando JSONKIT.

Ho già fatto in modo che JSON sia valido ... La stringa viene corrotta in qualche modo durante l'aggiunta di DidReceiveresponse?

È stato utile?

Soluzione

ha capito ... Ho avuto JSONKIT.H incluso nel progetto ma per un motivo strano, JSONKIT.M non è stato incluso nelle "Compile Fonti" sotto "Build Fases" - Una volta aggiunto manualmente ha iniziato a lavorareBene.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top