美文网首页
解析json字符串

解析json字符串

作者: Fisher123 | 来源:发表于2017-12-29 22:40 被阅读7次
//iOS解析json字符串
- (NSMutableArray *)commentFromJsonStr:(NSString *)jsonStr {
    NSMutableArray *commentDataArr = [[NSMutableArray alloc]init];
    if (jsonStr == nil || [jsonStr isEqualToString:@""] ) {
        return nil;
    }
    NSData *jsonData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
    NSArray *dataArray = [CommentModel mj_objectArrayWithKeyValuesArray:dic];
    for (CommentModel *model in dataArray) {
        [commentDataArr addObject:model];
    }
    return commentDataArr;
}

相关文章

网友评论

      本文标题:解析json字符串

      本文链接:https://www.haomeiwen.com/subject/fhgwgxtx.html