简体   繁体   中英

Getting Null while converting NSString from NSMutableData?

I guess it would be a duplicate, In metaData I am getting "Live365" Stream metadata, but still I am asking I am getting null if I am using

NSLog(@"SONG META :%@", [[NSString alloc] 
       initWithData:metaData encoding:NSUTF8StringEncoding]);

and it's printing ASCII values if I am using

NSLog(@"SONG META :%@", [[NSString alloc] 
         initWithData:metaData encoding:NSASCIIStringEncoding]); 

I have tried below schemes but getting null:

   NSUTF8StringEncoding
   NSUTF16BigEndianStringEncoding
   NSUTF16LittleEndianStringEncoding
   NSUTF32BigEndianStringEncoding
   NSUTF32StringEncoding

You have to make sure your NSMutableData object is indeed complete. If you download it from a web service you should only alloc-init the string after the download has finished.

If it is a valid string, your method should work fine.

If not, it is not a valid string and the results is expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM