将String转化成java对象
程序员文章站
2022-03-31 09:35:50
...
import com.alibaba.fastjson.JSONObject;
public void getObject () throws NoSuchMethodException {
JSONObject object1 = new JSONObject();
object1.put("openid","123");
object1.put("mobile","131313020");
object1.put("status","1");
List<String> p = new ArrayList<>();
p.add("hello");
p.add("hi");
object1.put("hobbys",p);
System.out.println("object1:"+object1);
JWJTest parse = (JWJTest)JSONObject.parseObject(object1.toString(), JWJTest.class);
System.out.println("parse:"+parse);
List<String> hobbys = parse.getHobbys();
System.out.println("hobbys:"+hobbys);
}
@Data
public class JWJTest {
String mobile;
String openid;
String status;
List<String> hobbys;
}
上一篇: 实用jQuery代码段
下一篇: 点云pcd格式与ply格式互相转换