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.
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
Actually
Here
rexists, but thelogcatofAndroid Studiodoes not display it, and the line break underwinis notr, so it is not discovered immediately. If you take this string and go tocontains ("r")What is returned at this time istrue, which proves that there isrin the string, haha