帶百分比符號的資料轉json

來源:互聯網
上載者:User

標籤:style   io   ar   color   os   sp   java   strong   on   

今天處理前後資料轉送的時候遇到了問題。

前台拼參數是這樣寫的 ‘&rowData=‘ + JSON.stringify(rowData);後台解析出的對象卻總是null,而且沒有拋ParseException,具體寫法如下:  DifferenceReportItem item = JSON.parse(rowDataToSelect, DifferenceReportItem.class);
entity檢查了,沒有錯誤。在debug後台接收的資料發現。後台接到的資料是這樣的{"timelyRateName":" 合 計","should_be":"2181","real_be":"358","undelivered_exceeded":"1231","delivered_exceeded":"101","undelivered_unexceeded":"491","rate_be":"16.02,"reportKey":"category_report"},莫名其妙少了“,多了個空格,成了這樣"rate_be":"16.0 2,果斷懷疑是%的問題。於是前台做了如下處理:        var rateBeStr = rowData.rate_be;
        rateBeStr = rateBeStr.substring(0,rateBeStr.length-1);
        rowData.rate_be = rateBeStr+"%25";
解析完畢的json:{"timelyRateName":"合計","should_be":"2181","real_be":"358","undelivered_exceeded":"1231","delivered_exceeded":"101","undelivered_unexceeded":"491","rate_be":"16.0%","reportKey":"category_report"}OK,問題解決!總結:JSON.stringify()函數處理串時會做轉碼,在有特殊符號的時候一定要注意轉換。在java代碼中,把json解析成的對象為null而不報異常,就要看看串中是不是有特殊符號了。歡迎留言說下遇到的其他特殊符號。

帶百分比符號的資料轉json

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.