我向API发出请求,这是接收返回的NSData:
{"word":"Ma\u00f1ana reposado"}
我试图用它来显示带有这些数据的标签,但是当我用它解析时:
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:1 error:&error];
NSString *里面[json ObjectForKey:@" word"] =" Ma?ana reposado"
如何解析NSData的正确方法?
答案 0 :(得分:0)
如果数据未以空值终止,请使用initWithData:encoding
NSString* yourNSString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
如果数据以空值终止,请使用stringWithUTF8String:以避免在末尾添加额外的\ 0(NUL终结符)
NSString* yourNSString = [NSString stringWithUTF8String:[responseData bytes]];