关于AFN 解析不标准的json格式问题

这个问题主要是json数据不标准,包含有 \n \r \t 等制表符

网上参考

AFN解决方法 搜索 AFURLResponseSerialization.m

在大概在256行

     if (responseString && ![responseString isEqualToString:@" "]) {

后面添加以下代码

NSCharacterSet *controlChars = [NSCharacterSet controlCharacterSet];

            NSRange range = [responseString rangeOfCharacterFromSet:controlChars];

            if (range.location != NSNotFound)

            {

                NSMutableString *mutable = [NSMutableString stringWithString:responseString];

                while (range.location != NSNotFound)

                {

                    [mutable deleteCharactersInRange:range];

                    range = [mutable rangeOfCharacterFromSet:controlChars];

                }

                responseString = mutable;

            }

或者有空字符串替换

 responseString = [responseString stringByReplacingOccurrencesOfString:@"\r\n"withString:@""];

    responseString = [responseString stringByReplacingOccurrencesOfString:@"\n"withString:@""];

    responseString = [responseString stringByReplacingOccurrencesOfString:@"\t"withString:@""];



你可能感兴趣的:(关于AFN 解析不标准的json格式问题)