map格式和string格式转化为json格式
发布日期:2025-04-12 01:09:45 浏览次数:10 分类:精选文章

本文共 1440 字,大约阅读时间需要 4 分钟。

Map到JSONObject的转换

Map<String, Object> data;
JSONObject dataJson = new JSONObject(data);
String cano = dataJson.get("CarNO");

String到JSONObject的转换

例如:
String results = saveorUpdateServices.execute(params, type);
System.out.println("*********results:" + results);
JSONObject dataJson = new JSONObject();
com.alibaba.fastjson.JSONObject dataJson = new com.alibaba.fastjson.JSONObject();

JSONObject er = (JSONObject) dataJson.parse(results);

int success = Integer.valueOf(er.get("success").toString());

例如:

String results = EntityUtils.toString(response.getEntity());
JsonObject json = new JsonParser().parse(results).getAsJsonObject();
int resultCode = json.get("resultCode").getAsInt();
System.out.println("querypersonsbycar-SUCCESS:获取人员卡信息成功没有信息时的数据! 信息如下:" + json);

如果(resultCode == 0) {

JsonElement dataItems = json.get("dataItems");
String到Map、Map到JSONObject的转换
例如:
results = queryorder.payordermihelp(orderno, "Weixin", null, "蜜服务测试", 1, null, null, 1, null, null, null, "测试", null, "691152", "", "", null, "wxc992e3bd110b5b87", openid);

Map mihelpmap = net.sf.json.JSONObject.fromObject(results);

com.alibaba.fastjson.JSONObject dataJson = new com.alibaba.fastjson.JSONObject(mihelpmap);

String到Map的转换

import com.alibaba.fastjson;
String str = "";
HashMap hashMap = JSON.parseObject(str, HashMap.class);

Map到String的转换

String paramMap = JSONObject.toJSONString(map);

Map到JSONObject的转换

JSONObject jsont = JSONObject.parseObject(paramMap);

上一篇:Map的深浅拷贝的探究
下一篇:Map排序

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年05月23日 12时48分11秒