将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");
相关推荐
Warson_L1 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅1 天前
海天线算法的前世今生
python·计算机视觉
韩师傅1 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L1 天前
LangGraph的MessageState and HumanMessage
python
韩师傅1 天前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L1 天前
python的类&继承
python
Warson_L1 天前
类型标注/type annotation
python
ThreeS1 天前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵1 天前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏
AlfredZhao1 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80