将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");
相关推荐
pengyi87101527 分钟前
动态IP池快速更换实操方案,5分钟完成IP替换
服务器·网络·tcp/ip
不做无法实现的梦~42 分钟前
Linux 上使用 CLion 开发嵌入式,并用 Codex CLI
linux·运维·服务器
张3231 小时前
Ansible拆分大型Playbook
linux·ansible
步辞1 小时前
Go语言怎么用channel做信号通知_Go语言channel信号模式教程【完整】
jvm·数据库·python
Ulyanov1 小时前
《PySide6 GUI开发指南:QML核心与实践》 第一篇:GUI新纪元——QML与PySide6生态系统全景
开发语言·python·qt·qml·雷达电子对抗
曲幽1 小时前
FastAPI + SQLAlchemy 2.0 通用CRUD操作手册 —— 从同步到异步,一次讲透
python·fastapi·web·async·sqlalchemy·session·crud·sync·with
被摘下的星星1 小时前
以太网技术
服务器·网络
Dxy12393102161 小时前
Python 如何使用 XPath 定位元素:从入门到实战
python
用户8356290780511 小时前
Python 设置 PowerPoint 文档属性与页面参数
后端·python
weixin_424999362 小时前
mysql行级锁失效的原因排查_检查查询条件与执行计划
jvm·数据库·python