当前位置:网站首页>Fastjson parses multi-level JSON strings
Fastjson parses multi-level JSON strings
2022-07-28 12:35:00 【When can the dead wood spring】
Json character string :
{
"status":0,"result":{
"location":{
"lng":120.32521556751674,"lat":31.66420355596458},"precise":1,"confidence":75,"comprehension":57,"level":" Building number "}}
Code demonstration :
JSONObject object = JSONObject.parseObject(response).getJSONObject("result").getJSONObject("location");
acc.setAccLng(object.getObject("lng", Double.class));
acc.setAccLat(object.getObject("lat", Double.class));
Complete code :
package com.ruoyi.sc.task;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.sc.domain.ScAcc;
import com.ruoyi.sc.service.IScAccService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.List;
/** * @Author: xinglibao * @Date: 2022/7/9 22:54 */
@Component("scTask")
public class ScTask {
@Autowired
private IScAccService scAccService;
@Autowired
private RestTemplate restTemplate;
public void scUpdateLng() {
// RestTemplate restTemplate = new RestTemplate();
List<ScAcc> scAccs = scAccService.selectLngIsNull();
for (ScAcc acc : scAccs) {
String url = "https://api.map.baidu.com/geocoding/v3/?address={" + acc.getAccLocation() + "&output=json&ak=tle20HLPKSLCpcUS8XP3IhpR9ZsNL6X1";
// {"status":0,"result":{"location":{"lng":120.32521556751674,"lat":31.66420355596458},"precise":1,"confidence":75,"comprehension":57,"level":" Building number "}}
String response = restTemplate.getForObject(url, String.class);
/*JSONObject jsonObject1 = JSONObject.parseObject(response); String result = jsonObject1.getString("result"); JSONObject jsonObject2 = JSONObject.parseObject(result); String location = jsonObject2.getString("location"); JSONObject jsonObject3 = JSONObject.parseObject(location); acc.setAccLng(jsonObject3.getObject("lng", Double.class)); acc.setAccLat(jsonObject3.getObject("lat", Double.class));*/
JSONObject object = JSONObject.parseObject(response).getJSONObject("result").getJSONObject("location");
acc.setAccLng(object.getObject("lng", Double.class));
acc.setAccLat(object.getObject("lat", Double.class));
scAccService.updateScAcc(acc);
}
}
}
brother
Happy songfanping kept laughing when he walked out of the photo studio , His happiness infected Li Lan , As they walked on , These two people have been laughing , Then Li baldheaded and Song Gang also giggled , Although the two children don't know why they laugh .
Remarried Li Lan was jubilant , Since her former husband drowned in the toilet , She survived seven years rather than death , Her hair has been in a doghouse for seven years , Now she has recovered her girl's pigtails , Also tied two red ropes at the end of the braid . Her face * It's like eating ginseng, and it suddenly turns ruddy , Her migraine headache suddenly disappeared , After hissing for seven years, her mouth began to hum a song . Her remarried husband is also red , As he walked in and out of the room, his feet thumped like drums , When he peed against the wall outside, it sounded like a storm .
This two married couple were like glue in their honeymoon , Once they seize the leisure, they will hide in the inner room , And the door is closed . Li baldhead and Song Gang can only fantasize in the outside room , The two children heard their mouths crackling when they were inside , Firmly believe that they hide inside and eat that bag of white rabbit milk candy . They not only eat during the day , In the evening, I can't stop eating . Before dark, they would force Li baldhead and Song Gang to go to bed , They shut themselves in the back room , Two mouths keep ringing . At this time, the neighbor's children were still running and shouting outside , Li baldhead and Song Gang can only go to bed , Songfanping and Li Lan also went to bed , But their mouths kept ringing in the room inside . Li baldheaded and Song Gang fell asleep with tears and drooling , When I woke up the next morning, my tears dried up , Saliva is still flowing .
————————————————
Copyright notice : This paper is about CSDN Blogger 「 When can the dead wood fall in spring 」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/weixin_45953673/article/details/125686838
边栏推荐
- 卸载 Navicat:正版 MySQL 官方客户端,真香!
- Functions and pointers in 08 go language
- 【Try to Hack】AT、SC、PS命令提权
- Notes on using objectanimator
- Solve the PHP prompt warning: division by zero in error
- Brief discussion on open source OS distribution
- AsiaInfo technology released antdb7.0, a "Telecom grade" core transaction database, to help government and enterprises "trust" to create the future!
- Basic use of JSON server
- 用C语言开发NES游戏(CC65)11、Metatiles
- 论治理与创新 | 2022 开放原子全球开源峰会 OpenAnolis 分论坛圆满召开
猜你喜欢

Image filter from the perspective of convolution

Is it overtime to be on duty? Take up legal weapons to protect your legitimate rights and interests. It's time to rectify the working environment

Laravel form data validation

Distributed timer

腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?

Knowledge points of MySQL (13)

Implementation method of mouse hover, click and double click in ue4/5

laravel表单数据验证

Google Earth engine (GEE) -- problems in the use of coordinate projection and reduceresolution functions in image downscaling

用C语言开发NES游戏(CC65)11、Metatiles
随机推荐
用C语言开发NES游戏(CC65)03、VRAM缓冲区
On Governance and innovation | the openanolis sub forum of the 2022 open atom global open source summit was successfully held
Using Arduino to develop esp8266 to build a development environment
Launcher sample code
How does musk lay off staff?
MySQL之知识点(十三)
Huawei releases harmonyos 3 and all scene new products, and the smart experience goes further
[dark horse morning post] LETV 400 employees have no 996 and no internal papers; Witness history! 1 euro =1 US dollar; Stop immediately when these two interfaces appear on wechat; The crackdown on cou
Lyscript get previous and next instructions
php 日期计算操作处理,当前日期加一天和指定日期减一天
Laravel $object->updated_at 返回的是Carbon对象,如何返回正常时间格式
Functions and pointers in 08 go language
Laravel之缓存
What if the instruction set umi2 is missing? PTK installation cannot be carried out
Yan Ji lost Beijing again, and more than half of the stores in the country were closed
Several ways to bind controls --butterknife/viewbinding/databinding
Open source huizhichuang future | 2022 open atom global open source summit openatom openeuler sub forum was successfully held
Force buckle 7_ 1672. Total assets of the richest customers
【一知半解】零值拷贝
php保留两位小数的几种方法介绍