[Java中将数据转JSON]

时间:2025-03-28 12:37:14

1.将List集合数据转成JSON

JSONObject merchantJson = new JSONObject();
JSONArray merchantList= ((mList));
("merchant",merchantList);

2.解析List集合的JSON

获取到封装成JSON的集合数据
String requestJsonString = ("merchant");
("接收请求参数======"+requestJsonString)
Merchant  集合中单个的实体类
//进行解析
List<Merchant> mList = (requestJsonString, );

3.将普通请求参数转成JSON

String json = ("请求参数,实体类或者map都可以");

4.解析JSON

 
JSONObject jsonObject = (json);
将参数封装入实体类
ResultResponse resultResponse = ()