1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Java Json数据中有双引号未转义的解析报错

Java Json数据中有双引号未转义的解析报错

时间:2020-08-07 01:31:29

相关推荐

Java Json数据中有双引号未转义的解析报错

例如Json数据中有双引号,解析时会报Json格式错误或者转义有问题

{"content": "重要任务提醒","matterName": ""德勤57"装砂滞留船期损失案"}

可以在解析前现将Json格式化一遍,这里面主要是双引号匹配的查找

public static String formatErrorJson(String s) {char[] temp = s.toCharArray();int n = temp.length;for (int i = 0; i < n; i++) {if (temp[i] == ':' && temp[i + 1] == '"') {for (int j = i + 2; j < n; j++) {if (temp[j] == '"') {if (temp[j + 1] != ',' && temp[j + 1] != '}') {temp[j] = '”';} else if (temp[j + 1] == ',' || temp[j + 1] == '}') {break;}}}}}return new String(temp);}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。