Java如何處理json字符串value多余雙引號
一、錯誤場景
json字符串的value值中有多余的雙引號。
錯誤的json字符串
二、處理方案
自己寫個方法將value值中多余的雙引號替換為 中文雙引號:
// 處理json字符串中value多余的雙引號, 將多余的雙引號替換為中文雙引號 private static String toJsonString(String s) { char[] tempArr = s.toCharArray(); int tempLength = tempArr.length; for (int i = 0; i < tempLength; i++) { if (tempArr[i] == ’:’ && tempArr[i + 1] == ’'’) {for (int j = i + 2; j < tempLength; j++) { if (tempArr[j] == ’'’) { if (tempArr[j + 1] != ’,’ && tempArr[j + 1] != ’}’) { tempArr[j] = ’”’; // 將value中的 雙引號替換為中文雙引號 } else if (tempArr[j + 1] == ’,’ || tempArr[j + 1] == ’}’) { break; } }} } } return new String(tempArr); }}
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. JAMon(Java Application Monitor)備忘記2. js的一些潛在規(guī)則使用分析3. 如何用 Python 制作一個迷宮游戲4. 讓chatgpt將html中的圖片轉(zhuǎn)為base64方法示例5. IntelliJ IDEA設(shè)置默認瀏覽器的方法6. Python PyQt5中彈出子窗口解決子窗口一閃而過的問題7. NetCore 配置Swagger的詳細代碼8. Python基于pyjnius庫實現(xiàn)訪問java類9. php設(shè)計模式之備忘模式分析【星際爭霸游戲案例】10. python怎樣讀取txt文件的數(shù)據(jù)內(nèi)容
