后台返回的数据格式如下:
detail = [{"title":"商品情景","content":"<p><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/2c3f2bfd22106d0f12503f13155b036d0a6a.jpeg\"></p>","width":1030,"height":349},
{"title":"原创设计","content":"<p><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/9b71a1a6e1be2a0126ad0479fb73861cb224.jpeg\"></p><p><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/6144d00508f7ea39ffffb269796b8ae33b05.jpeg\"></p><p><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/6b84023cfd3b39e07770cd11431eb6aed12c.jpeg\"></p><p><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/d62315cb67a72aaf88c2f7fac750dbbdbe4d.jpeg\"></p>","width":1030,"height":349},
{"title":"商品展示","content":"<p><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/7028325b953e85234e6ff14ca751f5ca465e.jpeg\"><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/908b322eccb8036aecad6f4759cb5c506572.jpeg\"><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/b39daa96e25a7675561e38cf4021cc69cd0b.jpeg\"><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/97e8a86a4f55f9a9d33a881b613fd3e67262.jpeg\"></p>","width":1030,"height":349},
{"title":"材质解析","content":"<p><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/66c988d5b0ada23f663d35b65ee980798a55.jpeg\"></p>","width":1030,"height":349},
{"title":"商品实拍","content":"<p><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/b29b7e5eda2e5152f13e0f6b98767c92dd2a.jpeg\"><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/28313ceae10350665f4722e0d5c507100097.jpeg\"><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/9ffb59e8d43a5136391d64dc851108f48a32.jpeg\"></p>","width":1030,"height":349},
{"title":"商品尺寸","content":"<p><img src=\"http://knife-develop.oss-cn-shanghai.aliyuncs.com/itemEditor/23bc14b27fd078a613254dd1129f0d32ec29.gif\"></p>","width":1030,"height":349}];
解析数据并展示
//字符串转jason(图文详情)
NSArray *array = [self arrayWithJsonString:self.model.detail];
NSString *string = @"";
for (NSDictionary *dic2 in array) {
NSString *string1 = dic2[@"content"];
string = [string stringByAppendingString:string1];
CGFloat height = [dic2[@"height"] floatValue];
CGFloat width = [dic2[@"width"] floatValue];
if (width > SCREEN_WIDTH) {
height = (SCREEN_WIDTH*height)/width;
}
self.cellHeight += height;
}
self.model.htmlString = string;
字符串转jason
///字符串转jason
- (NSArray *)arrayWithJsonString:(NSString *)jsonString {
if (jsonString == nil) {
return nil;
}
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
if(error) {
NSLog(@"json解析失败:%@",error);
return nil;
}
return array;
}
用WKWebView加载展示
[self.webView loadHTMLString:urlString baseURL:nil];