Introduction:
Although it is a small problem, I still need to record it. We know that Google provides a Gson framework to make it more efficient. Common objects are generally VO better.) and the conversion between json strings. Because most conversions work with browsers, the default Gson will escape html escape, but some special fields, for example, we have an authToken which is base64 encoding, at this time, we need to keep its original value followed by 0 or two equal signs =, rather than url escape.
Solution:
In this case, we cannot use the default Gson. Instead, we need to create a new GsonBuilder, disable the html escape function of this GsonBuilder, and then use the Gson created by it for conversion, we can achieve our goal.
Example:
Suppose we have a VO:
650) this. width = 650; "src =" http://img1.51cto.com/attachment/201309/095342478.png "title =" 37.png" alt = "095342478.png"/>
It contains a field and cannot be escaped. We must keep the original content (the content after base64 encoding ).
We write a program to test:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1446214110-1.png "title =" 38.png" alt = "095540689.png"/>
The test results are as follows:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/144621N29-2.png "title =" 40.png" alt = "095732217.png"/>
Conclusion:
It can be seen from this that the default Gson will perform html escape, And it will convert the "=" sign to \ u003d. If we use GsonBuilder and disableHtmlEscaping, let it create a Gson, and then use this Gson conversion, the result will not be html escape.
This article from "parallel line cohesion" blog, please be sure to keep this source http://supercharles888.blog.51cto.com/609344/1302450