I work with server. I send request to the server and it answers me in UTF-8 encoding, but when I try to decode byte array to the string, sometimes I get nil value. How can I decode this bytes array without any errors?
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString * result_string=[[[NSString alloc] initWithData:receivedData encoding:NSNonLossyASCIIStringEncoding] autorelease];
NSLog(result_string);
//...
}
when I convert using NSUTF8StringEncoding I get something like this:
xt”:””,”newstype”:[{“id”:”1″,”name”:”\u043f\u0440\u043e\u0438\u0441\u0448\u0435\u0441\u0442\u0432\u0438\u0435″,”ic
when I convert using NSNonLossyASCIIStringEncoding I get something like this:
xt”:””,”newstype”:[{“id”:”1″,”name”:”происшествие”,”ic
but sometimes, converting using NSNonLossyASCIIStringEncoding, I get errors. I don’t know why
I don’t know why this error happened. I fixed it like this: