Java如何處理json字符串value多余雙引號(hào)
一、錯(cuò)誤場景
json字符串的value值中有多余的雙引號(hào)。
錯(cuò)誤的json字符串
二、處理方案
自己寫個(gè)方法將value值中多余的雙引號(hào)替換為 中文雙引號(hào):
// 處理json字符串中value多余的雙引號(hào), 將多余的雙引號(hào)替換為中文雙引號(hào) 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中的 雙引號(hào)替換為中文雙引號(hào) } else if (tempArr[j + 1] == ’,’ || tempArr[j + 1] == ’}’) { break; } }} } } return new String(tempArr); }}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 怎樣才能用js生成xmldom對象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?2. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)車輛管理系統(tǒng)3. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算4. ASP.Net MVC利用NPOI導(dǎo)入導(dǎo)出Excel的示例代碼5. jstl 字符串處理函數(shù)6. JSP動(dòng)態(tài)網(wǎng)頁開發(fā)原理詳解7. PHP中為什么使用file_get_contents("php://input")接收微信通知8. XML CDATA是什么?9. IOS蘋果AppStore內(nèi)購付款的服務(wù)器端php驗(yàn)證方法(使用thinkphp)10. .Net core Blazor+自定義日志提供器實(shí)現(xiàn)實(shí)時(shí)日志查看器的原理解析
