Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSString from [NSData dataWithContentsOfURL:]

There is probably a really simple answer for this, but I can't seem to put my finger on it.

I am getting the contents of a web URL using (See Below)

NSData *data = [NSData dataWithContentsOfURL:webURL];

What I want to do is display this NSData in a readable form, not the hexadecimal representation.

like image 847
fuzzygoat Avatar asked Mar 24 '26 22:03

fuzzygoat


2 Answers

This is also another way, bypassing the use of NSData altogether:

NSError *error = nil;
NSString *string = [NSString stringWithContentsOfURL:webURL encoding:NSUTF8StringEncoding error:&error];
like image 137
Diziet Avatar answered Mar 26 '26 12:03

Diziet


NSString* newStr = [[NSString alloc] initWithData:data
                                         encoding:NSUTF8StringEncoding];
like image 41
Ashraf Avatar answered Mar 26 '26 12:03

Ashraf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!