Unescaped control character around character

本文介绍了解决AFNetworking在处理包含特殊字符的JSON数据时出现的Unescaped control character错误的方法。通过修改AFAFURLResponseSerialization.m文件中的responseObjectForResponse方法,实现过滤掉引起解析失败的控制字符。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

AFNetworking报错 Unescaped control character around character


原因可能是后台返回的数据里面有特殊字符,json解析不了。

拿到数据看了一下:

红框里面的字符串有问题(tab)

下面提供解决方法:

修改 AFAFURLResponseSerialization.m文件中的这个方法里面

- (id)responseObjectForResponse:(NSURLResponse *)response

                           data:(NSData *)data

                          error:(NSError *__autoreleasing *)error


-(NSString *)removeUnescapedCharacter:(NSString *)inputStr

{

    NSCharacterSet *controlChars = [NSCharacterSet controlCharacterSet];

    NSRange range = [inputStr rangeOfCharacterFromSet:controlChars];

    if (range.location != NSNotFound)

    {

        NSMutableString *mutable = [NSMutableString stringWithString:inputStr];

        while (range.location != NSNotFound)

        {

            [mutable deleteCharactersInRange:range];

            range = [mutable rangeOfCharacterFromSet:controlChars];

        }

        return mutable;

    }

    return inputStr;

}



‘{“destination”:“”,“dbName”:“crmworkbench”,“tblName”:“workorder_info”,“opType”:“INSERT”,“exeTime”:1752760953000,“seq”:1690464218513568,“endTran”:true,“cells”:[{“key”:true,“updated”:true,“colName”:“id”,“colValue”:“6109346”,“toNull:false,“currentColName”:“id”},{“key”:false,“updated”:true,“colName”:“uniqueid”,“colValue”:“b4a33e7a6d6147dabc4049aad5d2fe9f”,“toNull:false,“currentColName”:“uniqueid”},{“key”:false,“updated”:true,“colName”:“mobile”,“colValue”:“”,“toNull:true,“currentColName”:“mobile”},{“key”:false,“updated”:true,“colName”:“record_number”,“colValue”:“”,“toNull:true,“currentColName”:“record_number”},{“key”:false,“updated”:true,“colName”:“work_order_number”,“colValue”:“S20250717215748751053”,“toNull:false,“currentColName”:“work_order_number”},{“key”:false,“updated”:true,“colName”:“work_order_type”,“colValue”:“S”,“toNull:false,“currentColName”:“work_order_type”},{“key”:false,“updated”:true,“colName”:“parent_work_order_number”,“colValue”:“P20250717173522119910”,“toNull:false,“currentColName”:“parent_work_order_number”},{“key”:false,“updated”:true,“colName”:“handle_user_id”,“colValue”:“3087”,“toNull:false,“currentColName”:“handle_user_id”},{“key”:false,“updated”:true,“colName”:“handle_group_id”,“colValue”:“206”,“toNull:false,“currentColName”:“handle_group_id”},{“key”:false,“updated”:true,“colName”:“handle_group_name”,“colValue”:“枭龙云-客服关怀组”,“toNull:false,“currentColName”:“handle_group_name”},{“key”:false,“updated”:true,“colName”:“handle_user_name”,“colValue”:“吴琼林”,“toNull:false,“currentColName”:“handle_user_name”},{“key”:false,“updated”:true,“colName”:“handle_type”,“colValue”:1”,“toNull:false,“currentColName”:“handle_type”},{“key”:false,“updated”:true,“colName”:“handle_status”,“colValue”:0”,“toNull:false,“currentColName”:“handle_status”},{“key”:false,“updated”:true,“colName”:“urge_num”,“colValue”:0”,“toNull:false,“currentColName”:“urge_num”},{“key”:false,“updated”:true,“colName”:“message_status”,“colValue”:0”,“toNull:false,“currentColName”:“message_status”},{“key”:false,“updated”:true,“colName”:“repeat_call_total”,“colValue”:0”,“toNull:false,“currentColName”:“repeat_call_total”},{“key”:false,“updated”:true,“colName”:“emergency_code”,“colValue”:“2”,“toNull:false,“currentColName”:“emergency_code”},{“key”:false,“updated”:true,“colName”:“emergency_name”,“colValue”:“高风险”,“toNull:false,“currentColName”:“emergency_name”},{“key”:false,“updated”:true,“colName”:“task_id”,“colValue”:17726542”,“toNull:false,“currentColName”:“task_id”},{“key”:false,“updated”:true,“colName”:“partner”,“colValue”:1”,“toNull:false,“currentColName”:“partner”},{“key”:false,“updated”:true,“colName”:“customer_appeal_code”,“colValue”:“4”,“toNull:false,“currentColName”:“customer_appeal_code”},{“key”:false,“updated”:true,“colName”:“customer_appeal_name”,“colValue”:“网络投诉平台”,“toNull:false,“currentColName”:“customer_appeal_name”},{“key”:false,“updated”:true,“colName”:“prev_handle_user_id”,“colValue”:“”,“toNull:true,“currentColName”:“prev_handle_user_id”},{“key”:false,“updated”:true,“colName”:“prev_handle_user_name”,“colValue”:“”,“toNull:true,“currentColName”:“prev_handle_user_name”},{“key”:false,“updated”:true,“colName”:“prev_handle_group_id”,“colValue”:“”,“toNull:true,“currentColName”:“prev_handle_group_id”},{“key”:false,“updated”:true,“colName”:“prev_handle_group_name”,“colValue”:“”,“toNull:true,“currentColName”:“prev_handle_group_name”},{“key”:false,“updated”:true,“colName”:“prev_handle_type”,“colValue”:“”,“toNull:true,“currentColName”:“prev_handle_type”},{“key”:false,“updated”:true,“colName”:“prev_handle_time”,“colValue”:“”,“toNull:true,“currentColName”:“prev_handle_time”},{“key”:false,“updated”:true,“colName”:“description”,“colValue”:“【客户诉点】:一直发信息威胁恐吓,说爆通讯录怎么样的\n【客户提供凭证】:必须填。已提供\n【需协助】:烦请核实催收是否违规”,“toNull:false,“currentColName”:“description”},{“key”:false,“updated”:true,“colName”:“close_time”,“colValue”:“”,“toNull:true,“currentColName”:“close_time”},{“key”:false,“updated”:true,“colName”:“create_org_id”,“colValue”:“524”,“toNull:false,“currentColName”:“create_org_id”},{“key”:false,“updated”:true,“colName”:“create_org_name”,“colValue”:“枭龙云-重庆关怀团队”,“toNull:false,“currentColName”:“create_org_name”},{“key”:false,“updated”:true,“colName”:“create_name”,“colValue”:“吴琼林”,“toNull:false,“currentColName”:“create_name”},{“key”:false,“updated”:true,“colName”:“create_id”,“colValue”:“3087”,“toNull:false,“currentColName”:“create_id”},{“key”:false,“updated”:true,“colName”:“create_time”,“colValue”:“2025-07-17 22:02:34”,“toNull:false,“currentColName”:“create_time”},{“key”:false,“updated”:true,“colName”:“update_id”,“colValue”:“3087”,“toNull:false,“currentColName”:“update_id”},{“key”:false,“updated”:true,“colName”:“update_name”,“colValue”:“吴琼林”,“toNull:false,“currentColName”:“update_name”},{“key”:false,“updated”:true,“colName”:“update_time”,“colValue”:“2025-07-17 22:02:34”,“toNull:false,“currentColName”:“update_time”},{“key”:false,“updated”:true,“colName”:“deleted”,“colValue”:0”,“toNull:false,“currentColName”:“deleted”},{“key”:false,“updated”:true,“colName”:“system_code”,“colValue”:“ICRM”,“toNull:false,“currentColName”:“system_code”},{“key”:false,“updated”:true,“colName”:“case_no”,“colValue”:“”,“toNull:true,“currentColName”:“case_no”},{“key”:false,“updated”:true,“colName”:“cur_handle_system_code”,“colValue”:“”,“toNull:true,“currentColName”:“cur_handle_system_code”},{“key”:false,“updated”:true,“colName”:“result_sync_system”,“colValue”:“”,“toNull:true,“currentColName”:“result_sync_system”},{“key”:false,“updated”:true,“colName”:“lost_count”,“colValue”:“”,“toNull:true,“currentColName”:“lost_count”},{“key”:false,“updated”:true,“colName”:“receive_time”,“colValue”:“”,“toNull:true,“currentColName”:“receive_time”},{“key”:false,“updated”:true,“colName”:“last_follow_time”,“colValue”:“”,“toNull:true,“currentColName”:“last_follow_time”},{“key”:false,“updated”:true,“colName”:“message_type”,“colValue”:“”,“toNull:false,“currentColName”:“message_type”},{“key”:false,“updated”:true,“colName”:“inspect”,“colValue”:0”,“toNull:false,“currentColName”:“inspect”},{“key”:false,“updated”:true,“colName”:“extend_json”,“colValue”:“[{"englishName":"collectionNumbers","multiField":1,"values":[],"chineseName":"催收号码","fieldType":"STRING","desensitization":0,"required":0},{"englishName":"collectionedNumbers","desensitizationType":"MOBILE","multiField":1,"values":[],"chineseName":"被催号码","fieldType":"STRING","desensitization":1,"required":0},{"englishName":"decompressionCode","desensitizationType":"DECOMPRESSIONCODE","multiField":1,"values":[],"chineseName":"解压码","fieldType":"STRING","desensitization":1,"required":0},{"englishName":"caseDate","multiField":1,"values":[{"valueEnc":"[\"2025-06-28\",\"2025-07-17\"]","value":"[\"2025-06-28\",\"2025-07-17\"]"}],"chineseName":"案发时间","fieldType":"DATE_RANGE","desensitization":0,"required":1}]”,“toNull:false,“currentColName”:“extend_json”},{“key”:false,“updated”:true,“colName”:“expect_solve_time”,“colValue”:“”,“toNull:true,“currentColName”:“expect_solve_time”},{“key”:false,“updated”:true,“colName”:“appointment_call_start_time”,“colValue”:“”,“toNull:true,“currentColName”:“appointment_call_start_time”},{“key”:false,“updated”:true,“colName”:“appointment_call_end_time”,“colValue”:“”,“toNull:true,“currentColName”:“appointment_call_end_time”},{“key”:false,“updated”:true,“colName”:“brainmap_switch”,“colValue”:0”,“toNull:false,“currentColName”:“brainmap_switch”},{“key”:false,“updated”:true,“colName”:“is_service”,“colValue”:0”,“toNull:false,“currentColName”:“is_service”},{“key”:false,“updated”:true,“colName”:“stop_collection_end_time”,“colValue”:“”,“toNull:true,“currentColName”:“stop_collection_end_time”},{“key”:false,“updated”:true,“colName”:“out_call_enc”,“colValue”:“”,“toNull:false,“currentColName”:“out_call_enc”},{“key”:false,“updated”:true,“colName”:“mobile_enc”,“colValue”:“*mTBVhCm7osQ+lmA0jZ7hUYw==”,“toNull:false,“currentColName”:“mobile_enc”},{“key”:false,“updated”:true,“colName”:“last_follow_user_id”,“colValue”:“”,“toNull:true,“currentColName”:“last_follow_user_id”},{“key”:false,“updated”:true,“colName”:“last_follow_user_name”,“colValue”:“”,“toNull:true,“currentColName”:“last_follow_user_name”},{“key”:false,“updated”:true,“colName”:“last_follow_group_id”,“colValue”:“”,“toNull:true,“currentColName”:“last_follow_group_id”},{“key”:false,“updated”:true,“colName”:“last_follow_group_name”,“colValue”:“”,“toNull:true,“currentColName”:“last_follow_group_name”},{“key”:false,“updated”:true,“colName”:“detail_template_name”,“colValue”:“协助类-催收调查”,“toNull:false,“currentColName”:“detail_template_name”},{“key”:false,“updated”:true,“colName”:“urge_follow_flag”,“colValue”:0”,“toNull:false,“currentColName”:“urge_follow_flag”},{“key”:false,“updated”:true,“colName”:“back_follow_flag”,“colValue”:0”,“toNull:false,“currentColName”:“back_follow_flag”},{“key”:false,“updated”:true,“colName”:“belong_entity”,“colValue”:“MSXF”,“toNull:false,“currentColName”:“belong_entity”},{“key”:false,“updated”:true,“colName”:“credit_plate”,“colValue”:“”,“toNull:true,“currentColName”:“credit_plate”},{“key”:false,“updated”:true,“colName”:“register_mobile_enc”,“colValue”:“”,“toNull:true,“currentColName”:“register_mobile_enc”},{“key”:false,“updated”:true,“colName”:“call_identity”,“colValue”:03”,“toNull:false,“currentColName”:“call_identity”},{“key”:false,“updated”:true,“colName”:“icc_account”,“colValue”:125863”,“toNull:false,“currentColName”:“icc_account”},{“key”:false,“updated”:true,“colName”:“asset_belong”,“colValue”:“”,“toNull:true,“currentColName”:“asset_belong”},{“key”:false,“updated”:true,“colName”:“contract_source”,“colValue”:“”,“toNull:true,“currentColName”:“contract_source”}],“schemaId”:-1,“originalTopic”:“”,“odsBinlogColumnCount”:71,“odsCkbeanColumnCount”:71,“logName”:“mysql-bin.000147”,“startLogPos”:50717027,“endLogPos”:50717739,“uniqueKey”:“6109346”,“gtids”:“4558f21b-6543-11ef-9fef-fa163e1b683d:1-57769841”,“jsonType”:“canal_json”,“targetTopic”:“icrm_ljdatabuscrmworkbenchrw.msfinance.db_3306.crmworkbench.workorder_info”}’ 这些json为什么序列化失败
最新发布
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值