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
黄舟2017-07-04 13:47:28
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