美文网首页
关于用AFNetworking解析失败

关于用AFNetworking解析失败

作者: 低调的前行者灬 | 来源:发表于2017-01-10 10:36 被阅读0次

    报错

    **Error Domain=NSCocoaErrorDomain Code=3840 "Unexpected end of file during string parse (expected low-surrogate code point but did not find one)." UserInfo={NSDebugDescription=Unexpected end of file during string parse (expected low-surrogate code point but did not find one).}**
    

    解决方案
    利用JSONKit 地址https://github.com/johnezang/JSONKit
    解析时添加的代码

    
    return [self.netManager GET:url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
                NSError *error;
                id information = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
                DLog(@"解析错误信息==============%@",error);
    //关键代码
                if (error) {
                    error = nil;
                    id information = [responseObject objectFromJSONDataWithParseOptions:JKParseOptionLooseUnicode error:&error];
                    !success?:success(information);
                }
    //end
                !success?:success(information);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
                if (failure) {
                    failure(error);
                }
            }];
    

    相关文章

      网友评论

          本文标题:关于用AFNetworking解析失败

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