解析后台返回数据,实现图文详情

后台返回的数据格式如下:

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];
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值