2

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.

4
  • what type of resource is located at webURL ? Commented Jan 25, 2012 at 15:03
  • Its just a web page with text on it, I was hoping to scrape the text off it but maybe I am going about this the wrong way. Commented Jan 25, 2012 at 15:16
  • Using NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; seems to have worked, it does give me the html source but I can pick through that to get the data I need. Commented Jan 25, 2012 at 15:28
  • Do any of the current answers solve your problem? Commented Feb 1, 2012 at 16:00

4 Answers 4

7

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

NSError *error = nil;
NSString *string = [NSString stringWithContentsOfURL:webURL encoding:NSUTF8StringEncoding error:&error];
Sign up to request clarification or add additional context in comments.

Comments

3
NSString* newStr = [[NSString alloc] initWithData:data
                                         encoding:NSUTF8StringEncoding];

Comments

1

If this is just for display/logging, and you don't really need the string in your program, you can also set a breakpoint (click on the line numbers in the line you want to log).

Then right click the breakpoint you just created --> Edit breakpoint --> Click to add an action. Set the dropdown to debugger command, and in the Action text field, enter x/10s (char*)[data bytes]. This will write 10 "segments" of your data to the log. Check the Automatically continue... checkbox so the breakpoint doesn't halt the program.

NSData logging breakpoint in Xcode4

Comments

0
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", response);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.