search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

1 answers
Q&A android - How to ensure that "\r" is not cleared when Gson parses characters containing "\r"?

0
    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

Your Answer
submit

1 answers
0

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

2017-07-04 13:47:28

submit

Popular tool

vc9-vc14 (32+64 bit) runtime library collection (link below)

vc9-vc14 (32+64 bit) runtime library collection (link below)

Download the collection of runtime libraries required for phpStudy installation

VC9 32-bit

VC9 32-bit

VC9 32-bit phpstudy integrated installation environment runtime library

PHP programmer toolbox full version

PHP programmer toolbox full version

Programmer Toolbox v1.0 PHP Integrated Environment

VC11 32-bit

VC11 32-bit

VC11 32-bit phpstudy integrated installation environment runtime library

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use