当前位置: 代码迷 >> 综合 >> String转JSON,JSON转JAVA对象
  详细解决方案

String转JSON,JSON转JAVA对象

热度:0   发布时间:2024-02-11 01:04:35.0

首先导包:

import com.alibaba.fastjson.JSONObject;

String转JSON:

//result为要转JSON的String字符串
JSONObject jsonObject = JSONObject.parseObject(result);

JSON转JAVA对象:

//Object为要转JAVA对象,可以为任意JAVA类,例:Student-->
//Student student=(Student)JSONObject.toJavaObject(jsonObject, Student.class);
//jsonObject为要转JAVA对象的JSON
Object object=(Object)JSONObject.toJavaObject(jsonObject, Object.class);