将json字符串转换为json对象

java将json字符串转换为json对象

jsonObject:{"result":{"rows":[{"elements":[{"duration":7108,"distance":89836},{"duration":5377,"distance":89139},{"duration":60,"distance":0}]}]},"message":"Success","request_id":"282fb0796b3d4c2eb440c71ca29ed275","status":0}

java 复制代码
import com.alibaba.fastjson.JSONObject;



// 创建RestTemplate
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.postForEntity(url, data, String.class);
String body = response.getBody();
JSONObject jsonObject = (JSONObject) JSONObject.parse(body);
if (!"Success".equals(jsonObject.getString("message"))){
    return AjaxResult.error("地图计算距离失败");
}
log.info("返回参数:" + jsonObject);
JSONObject result = jsonObject.getJSONObject("result");
JSONArray rows = result.getJSONArray("rows");
JSONArray elements = rows.getJSONObject(0).getJSONArray("elements");
相关推荐
2501_948114241 小时前
星链4SAPI + OpenClaw实战:给GPT-5.4与Claude 4.6装上“职业传送门”
python·gpt·架构
脱脱克克2 小时前
OpenClaw 腾讯云 + 火山方舟(Volcengine Ark)完整安装与扩展教程
linux·腾讯云·openclaw
进击的小头2 小时前
第6篇:贝尔曼最优化理论
python·算法·动态规划
Arya_aa2 小时前
TCP和UDP协议
服务器
guodashen0072 小时前
在安卓端启动一个服务器接口,用于接收post请求的json数据
android·服务器·json
意疏2 小时前
openJiuwen实战:用AsyncCallbackFramework为Agent增强器添加可观测性
java·服务器·前端
马士兵教育2 小时前
2026年IT行业基本预测!计算机专业学生就业编程语言Java/C/C++/Python该如何选择?
java·开发语言·c++·人工智能·python·面试·职场和发展
cyber_两只龙宝2 小时前
【MySQL】MySQL主从复制架构
linux·运维·数据库·mysql·云原生·架构
Lolo_fi3 小时前
Linux PCI/PCIe子系统
linux