android - How to ensure that "\r" is not cleared when Gson parses characters containing "\r"?
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-07-04 13:45:28
0
1
1411
    String json = "{\"remark1\":\"这里是一个反斜杠 + r \r \r \r ------------- \",\"remark2\":\"这里是二个反斜杠 + r \\r \\r \\r ------------- \",\"remark3\":\"这里是三个反斜杠 + r \\\r \\\r \\\r ------------- \"}";

I have a Json string that I want to display and wrap in TextView, but during the actual operation, I use Gson to convert it into Bean## After the #object, "\r" will always be removed directly by Gson.

I tried

disableHtmlEscaping()It didn’t work!!!

PLog.json(json);

Gson gson = new GsonBuilder().disableHtmlEscaping().create();
Gson gson2 = new Gson();

ReMark shareLinkResponse = gson.fromJson(json, ReMark.class);
ReMark shareLinkResponse2 = gson2.fromJson(json, ReMark.class);
PLog.d(shareLinkResponse.getRemark1());
PLog.d(shareLinkResponse.getRemark2());
PLog.d(shareLinkResponse.getRemark3());
PLog.d("----------------------------------------");
PLog.d(shareLinkResponse2.getRemark1());
PLog.d(shareLinkResponse2.getRemark2());
PLog.d(shareLinkResponse2.getRemark3());

Show

in my LogCat

 {
     "remark1": "这里是一个反斜杠 + r \r \r \r ------------- ",
     "remark2": "这里是二个反斜杠 + r \r \r \r ------------- ",
     "remark3": "这里是三个反斜杠 + r \\r \\r \\r ------------- "
 }

D/PLog: [ (MainActivity.java:49)#onCreate ] 这里是一个反斜杠 + r    ------------- 
D/PLog: [ (MainActivity.java:50)#onCreate ] 这里是二个反斜杠 + r \r \r \r ------------
D/PLog: [ (MainActivity.java:51)#onCreate ] 这里是三个反斜杠 + r \ \ \ ------------- 
D/PLog: [ (MainActivity.java:52)#onCreate ] ----------------------------------
D/PLog: [ (MainActivity.java:53)#onCreate ] 这里是一个反斜杠 + r    ------------- 
D/PLog: [ (MainActivity.java:54)#onCreate ] 这里是二个反斜杠 + r \r \r \r ------------
D/PLog: [ (MainActivity.java:55)#onCreate ] 这里是三个反斜杠 + r \ \ \ ------------- 

If

Gson cannot be parsed correctly, I will have to do it manually, which is very embarrassing

HELP

女神的闺蜜爱上我
女神的闺蜜爱上我

reply all(1)
黄舟

Actually

这里是一个反斜杠 + r    -------------

Herer exists, but the logcat of Android Studio does not display it, and the line break under win is not r, so it is not discovered immediately. If you take this string and go to contains ("r") What is returned at this time is true, which proves that there is r in the string, haha

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!