我是 iOS Development 的新手。我只想从我的 Url 将“描述”关键数据加载到 UIWebView 这里我的 Url 就像
http://www.janvajevu.com/webservice/specific_post.php?post_id=2885
我为它解析了数据,就像
-(void)viewWillAppear:(BOOL)animated
{
[self.webSpinner startAnimating];
NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:@"http://www.janvajevu.com/webservice/specific_post.php?post_id=2885"]];
dispatch_async(kBgQueue, ^{
data = [NSData dataWithContentsOfURL: url];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
-(void)fetchedData:(NSData *)responsedata
{
if (responsedata.length > 0)
{
NSError* error;
self.webDictionary= [NSJSONSerialization JSONObjectWithData:responsedata options:kNilOptions error:&error];
self.webArray=[_webDictionary objectForKey:@"data"];
}
self.webViewString=[self.webArray valueForKey:@"description"];
NSString *descriptionString=[NSString stringWithFormat:@"%@",self.webViewString];
[self.webView loadHTMLString:descriptionString baseURL:nil];
然后它在 WebView 中打印数据,就像
"<img style='width: 100% !important; height: auto; margin: 30px 20px 30px 20px;' class=\"alignnone size-full wp-image-2967\" src=\"http://www.janvajevu.com/wp-content/uploads/2014/12/Amazing-talented-people-in-the-world.jpg\" alt=\"Amazing talented people in the world\" width=\"0\" height=\"0\" />\U0a9c\U0ac1\U0a93 \U0aa6\U0ac1\U0aa8\U0abf\U0aaf\U0abe \U0aa8\U0abe\U0a85\U0a9c\U0aac \U0a97\U0a9c\U0aac \U0a9f\U0ac7\U0ab2\U0ac7\U0a82\U0a9f\U0ac7\U0aa1 \U0ab2\U0acb\U0a95\U0acb<br />
\n<br />
\nhttps://www.youtube.com/watch?v=Vo0Cazxj_yc"
当我将它们编码为
NSData *webViewDatastring = [descriptionString dataUsingEncoding:[NSString defaultCStringEncoding]];
NSString *webUnicodeString = [[NSString alloc] initWithData:webViewDatastring encoding:NSNonLossyASCIIStringEncoding];
NSString *webViewString=[webUnicodeString stringByTrimmingCharactersInSet:charsToTrim];
并将它们加载到 WebView 中,就像
[self.webView loadHTMLString:webViewString baseURL:nil];
然后它返回 Null。因此,我对如何编码此 HTML 数据然后将其显示在 UIWebView 中感到困惑,请给我解决方案,否则请给我此类教程的资源。