user1746447
user1746447

Reputation: 61

Objective-C Display HTML File from Web Service

What methods are able to save byte data where in Java it is byte[] and then convert the byte array to string?

I'm retrieving an HTML file from web service where the HTML file is in byte. After convert the byte to string, it is displayed in UIWebView. I've tried to use NSData and initialized with initWithContentsOfFile but it does not work. The code as following:

NSData *htmlContent=[[NSData alloc] initWithContentsOfFile:[[[[[[[theDict   objectForKey:@"S:Envelope"] objectForKey:@"S:Body"] objectForKey:@"ns2:ReportResponse "] objectForKey:@"return"] objectForKey:@"Report"] objectForKey:@"report"] objectForKey:@ "text"]]; 

Upvotes: 1

Views: 342

Answers (1)

Rakesh
Rakesh

Reputation: 3399

NSData object will get created if your path is correct. Just make sure the path of the file you are giving is correct. Log the path that is being used.

I'm a bit confused about what you are getting from the web service. Is it the html file content? Or are you saving this to some file? Anyways using NSURLConnection you will be getting a final NSData object, I guess.

EDIT: Convert the NSData to NSString using the NSString method:

NSString *htmlString = [[NSString alloc] initWithData:<NSData object> encoding:NSUTF8Encoding];

And then maybe you could use the following method of UIWebView for displaying:

loadHTMLString:baseURL:

Upvotes: 1

Related Questions