将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");
相关推荐
把头塞进显示器1 分钟前
电商平台-测试报告
python·selenium·pytest
ShyanZh3 分钟前
【Python3基础】01-Python 环境与开发工具
python
醇氧7 分钟前
Git 合并冲突与`__pycache__` 的恩怨情仇
python·numpy·fastapi
Wang's Blog20 分钟前
Java 项目实战: 外卖平台-启用禁用员工账号与Long精度丢失修复
java·服务器
xiaoye-duck21 分钟前
《Linux 网络编程》深入理解数据链路层:从MAC帧到ARP协议的底层原理详解
linux·网络
ShyanZh29 分钟前
【Python3基础】02-输入输出与程序运行
python
伞伞悦读33 分钟前
【第39期】Python 第三方包安装详解:pip、conda、requirements、版本锁定和镜像源
python·conda·pip
Jialu.1 小时前
第7篇:舆情预警系统:三类规则引擎 + 飞书/钉钉 Webhook 通知
python·安全
渡我白衣1 小时前
HttpRequest与HttpResponse的实现
服务器·数据结构·c++·人工智能·tcp/ip·机器学习·caffe
刃神太酷啦1 小时前
前端入门第一课:HTML 基础语法 + 常用标签 + 实战全解
服务器·c语言·前端·javascript·css·c++·html