Java常用类型转换写法

1. json转字符串

String requestStr = JSON.toJSONString(requestObj);

2. json转对象

String responseStr =  HttpHelper.post(targetUrl, requestStr, token);
Object[] responseObj = JSON.parseObject(responseStr, Object[].class);

3. 一个对象成员变量值复制到另一对象中:

使用package org.springframework.beans;包下的BeanUtils.copyProperties(source, target);即可

BeanUtils.copyProperties(request, MDevice);

复制的数据在request中,使用时用.访问

4. 字符串转json:

String responseStr =  HttpHelper.post(url, requestStr, token);
JSONObject responseJson = (JSONObject) JSON.parse(responseStr);
发布了18 篇原创文章 · 获赞 9 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/xueyue616/article/details/83181641