JSON値に英語の二重引用符が含まれているため、JSON解析が失敗しました。
1116 ワード
説明:原紙は過去にあまりにも長く貼ってあったので、回復できませんでした。元の住所:https://bbs.csdn.net/topics/390578406?page=1噫new_ベスト (12階回答)
原文のコードにはいくつかの小さな問題があります。以下のコードはコロン(:)と引用符(")の間にスペース記号が存在する問題に対して最適化します。
原文のコードにはいくつかの小さな問題があります。以下のコードはコロン(:)と引用符(")の間にスペース記号が存在する問題に対して最適化します。
private static String jsonString(String s) {
char[] temp = s.toCharArray();
int n = temp.length;
for (int i = 0; i < n; i++) {
if (temp[i] == ':') {
int quentIndex = i + 1;
while (StringUtils.isBlank(String.valueOf(temp[quentIndex]))) {
quentIndex++;
}
if (temp[quentIndex] == '"') {
for (int j = quentIndex + 1; 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);
}