例如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);}