Json字符串转换处理html编码格式,= \u003d 处理
Json字符串转换处理html编码格式,= \u003d 处理
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; @JsonAutoDetect(fieldVisibility= JsonAutoDetect.Visibility.ANY, getterVisibility=JsonAutoDetect.Visibility.NONE)
public class JsonReqVo { @Expose
@SerializedName("Username") //gson
@JSONField(name= "Username") //fastjson
private String username; @Expose
@JsonProperty("Status")
private String status; //jackson @Expose
private String school;
@Expose
private String password;
@Expose
private String address; @JsonIgnore //可以直接放在field上面表示要忽略的filed //jackson
@Expose(serialize = false) //gson
@JSONField(serialize = false) //fastjson
private String apikey; public String getAddress() {
return address;
} public void setAddress(String address) {
this.address = address;
} public String getSchool() {
return school;
} public void setSchool(String school) {
this.school = school;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getStatus() {
return status;
} public void setStatus(String status) {
this.status = status;
} public String getApikey() {
return apikey;
} public void setApikey(String apikey) {
this.apikey = apikey;
}
} //测试类
import com.alibaba.fastjson.JSON;
import com.example.core.mydemo.json.vo.JsonReqVo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder; /**
* Gson={"Username":"tester\u003d\u003d\u003d","password":"#\n\n"}
* FASTJSON={"Username":"tester===","password":"#\n\n"}
* JACKSON={"username":"tester===","password":"#\n\n"}
*/
public class Json2Test { // 定义jackson对象
private static final ObjectMapper MAPPER = new ObjectMapper(); public static void main(String[] args) {
JsonReqVo req = new JsonReqVo();
req.setUsername("tester===");
req.setPassword("#\n\n"); GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
//设置属性:disableHtmlEscaping
Gson gson = builder.disableHtmlEscaping().create(); //Gson={"Username":"tester===","password":"#\n\n"} System.out.println("Gson=" + gson.toJson(req)) ; System.out.println("FASTJSON=" + JSON.toJSONString(req)) ;
JSONObject jobj = JSONObject.parseObject(json);
System.out.println("jobj1=" + jobj.get("Username").toString());
System.out.println("jobj2=" + jobj.get("password").toString());
try {
//过滤null属性
MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
System.out.println("JACKSON=" + MAPPER.writeValueAsString(req));
} catch (JsonProcessingException e) {
e.printStackTrace();
} }
}
Json字符串转换处理html编码格式,= \u003d 处理的更多相关文章
- C#中服务端接受前端JSON字符串转换成字典集合
我们是否可以把从前端接受的JSON字符串转换成字典集合呢? 比如从前端接收:{'size':'10', 'weight':'10kg'} 在服务端转换成:[{size:"10"}, ...
- json 字符串转换成对象,对象转换成json字符串
json 字符串转换成对象,对象转换成json字符串 前端: 方法一: parseJSON方法: [注意jquery版本问题] var str = '{"name":&qu ...
- json字符串转换成json对象,json对象转换成字符串,值转换成字符串,字符串转成值
一.json相关概念 json,全称为javascript object notation,是一种轻量级的数据交互格式.采用完全独立于语言的文本格式,是一种理想的数据交换格式. 同时,json是jav ...
- 使用jackson来进行数组格式的json字符串转换成List。
有一个字符串如下.如下,也是通过jackson把list转换成的json字符串,我想把它转过来,看网上的内容都不尽人如意,都是片断的内容.估计只有写的知道怎么使用,所以就直接看了jackson的官网, ...
- 特殊字符导致json字符串转换成json对象出错
在对数据库取出来的数据(特别是描述信息)里面含有特殊字符的话,使用JSON.parse将json字符串转换成json对象的时候会出错,主要是双引号,回车换行等影响明显,左尖括号和右尖括号也会导致显示问 ...
- JSON字符串转换成对象时候 需要有默认构造器 因为这是通过反射创建的 反射是先通过默认构造器创建对象的
JSON字符串转换成对象时候 需要有默认构造器 因为这是通过反射创建的 反射是先通过默认构造器创建对象的
- 转换成json字符串,与json字符串转换成java类型都要先转换成json对象
转换成json字符串,与json字符串转换成java类型都要先转换成json对象
- java 字符串转json,json转实体对象、json字符串转换成List、List转String、以及List排序等等...
@RequestMapping(value = "updateInvestorApplyAccountNo", method = RequestMethod.POST) @Resp ...
- JavaScript:将key和value不带双引号的JSON字符串转换成JSON对象的方法
遇到相关的问题,花了两天的时间来解决,深感来之不易,所以做如下的总结,希望遇到此问题的码农能更快的找到解决办法! var jsonArr= [{col:TO_CHAR(HZRQ,'YYYYMM'),t ...
- 小程序跳坑之JSON字符串转换JSON对象
常见的JSON字符串转换有很多,这里只讲我遇到过的小程序中用到的转换. 通常我们在小程序中用到的地方是,请求一个数据表或者请求一个接口,拿到了一堆数据,里面包含有各种字段数组,头像,图片,详情,地址, ...
随机推荐
- WPF 将 StaticResource 和 ResourceDictionary 放在一起的魔幻行为
本文将记录一些在 WPF 里面,使用 StaticResource 将 ResourceDictionary 玩坏的做法.大家可以放心的是,这些玩法基本只有高级玩家或逗比开发者才会使用到 后加入的资源 ...
- 开发日志:windows 服务器禁用TLS1.0和TLS1.1协议使网站更安全
SSL/TLS 的版本 协议 发布时间 状态 SSL 1.0 未公布 未公布 SSL 2.0 1995 年 已于 2011 年弃用 SSL 3.0 1996 年 已于 2015 年弃用 TLS 1.0 ...
- .Net项目部署到Docker
.Net项目部署到Docker 环境 linux docker .Net 7 步骤 编写Dockerfile 上传项目文件到linux 运行项目文件到docker 一.设置项目端口 在Program. ...
- 自动化测试数据生成:Asp.Net Core单元测试利器AutoFixture详解
引言 在我们之前的文章中介绍过使用Bogus生成模拟测试数据,今天来讲解一下功能更加强大自动生成测试数据的工具的库"AutoFixture". 什么是AutoFixture? Au ...
- C++指针与引用(Pointers OR References)
一.Pointers Pointer是指针,可以用来指向任何一个objects,包括一般变量: 1 int i = 3; 2 int * pi = &i; 3 cout << pi ...
- sendmail发送慢的问题
1.使用python的脚本,发送邮件.代码如下: 点击查看代码 [root@ZabbixServerMasterNode ~]# cd /etc/zabbix/alertscripts/ [root@ ...
- 使用Elasticsearch在Rails中进行全文本搜索
使用Elasticsearch在Rails中进行全文本搜索 参考: https://blog.csdn.net/cunjie3951/article/details/106921108
- iframe 高度设置为0时还有占位_iframe占位
iframe是一个内联元素,默认是跟baseline对齐的,iframe后边有个看不见.摸不着的行内空白节点,空白节点占据着高度,iframe与空白节点的基线对齐,导致了div被撑开,从而出现滚动条, ...
- ctfshow_web_1(困难题)
CTFshow web1(困难题) 根据前面做题经验,看见登录框基本都是跑一下爆破,弱口令等等 这里用 dirmap 目录爆破爆出来有一个 www.zip 把他下载下来 看了 login.php 和 ...
- ༺$Musique Collection 1$༻
~~头图~~ 自取捏 <\(Landslide\)>-\(Oh\,Wonder\) I know it hurts sometimes but You'll get over it You ...