当前位置:网站首页>Use fastjson JSON (simple and rough version)
Use fastjson JSON (simple and rough version)
2022-07-27 19:20:00 【The bearer of dark cuisine】
Reference blog :https://blog.csdn.net/qq877507054/article/details/51395852
First look at json The style of : Contains multiple arrays .
{
"status":0,
"message":"ok",
"total":134,
"results":[
{
"name":" The Beijing municipal dnf Primary school ",
"location":{
"lat":39.923629,
"lng":116.388059
},
"address":" Fuyou street C 27 Number ",
"province":" The Beijing municipal ",
"city":" The Beijing municipal ",
"area":" Xicheng district ",
"street_id":"8ca69c393be618bfc061e",
"telephone":"",
"detail":1,
"uid":"8ca69c70e393befc061e",
"detail_info":{
"tag":" Education and training ; Primary school ",
"navi_location":{
"lng":116.3887231398,
"lat":39.92324024956
},
"type":"education",
"detail_url":"",
"overall_rating":"0.0",
"children":[
]
}
},
{
"name":"dudu Primary school ( Suianbo campus )",
"location":{
"lat":39.922193,
"lng":116.430818
},
"address":" Jinbao Street 65 Number ",
"province":" The Beijing municipal ",
"city":" The Beijing municipal ",
"area":" Dongcheng District ",
"street_id":"9bdab243406c476051",
"detail":1,
"uid":"9bda75243406c476051",
"detail_info":{
"tag":" Education and training ; Primary school ",
"navi_location":{
"lng":116.431089492,
"lat":39.9215554065
},
"type":"education",
"detail_url":"",
"children":[
]
}
}
]
}
// The above json Stored as String type
String json = jsonlist.get(a).toString();
System.out.println("json:" + json);
// take JsonObject Data to Json
JSONObject object = JSON.parseObject(json);
System.out.println(object);
// obtain json In the middle of :results
Object results = object.get("results");
System.out.println("results:" + results);
// Convert to array
JSONArray array = JSON.parseArray(results.toString());
// Traverse the data
for(int b=0;b<array.size();b++){
System.out.println(array.get(b));
// This line has to write : Have to add +""; Otherwise, it will report the abnormal type of forced conversion !
String str = array.get(b)+"";
JSONObject resultsGetJson = JSON.parseObject(str);
//name
String name = resultsGetJson.get("name").toString();
System.out.println("name:" + name);
//address
String address = resultsGetJson.get("address").toString();
System.out.println("address:" + address);
//telephone Not every results It contains telephone
String telephone = "" ;
try {
telephone = resultsGetJson.get("telephone").toString();
System.out.println("telephone:" + telephone);
} catch (Exception e) {
// TODO: handle exception
}
// Get longitude and latitude information
String location = resultsGetJson.get("location").toString();
JSONObject locationJson = JSON.parseObject(location);
String locationLat = locationJson.get("lat").toString();
System.out.println("locationLat:" + locationLat);
String locationLng = locationJson.get("lng").toString();
System.out.println("locationLng:" + locationLng);
String detail_info = resultsGetJson.get("detail_info").toString();
System.out.println("detail_info:" + detail_info);
// take JsonObject Data to Json
JSONObject detail_infoJson = JSON.parseObject(detail_info);
String tag = "" ; String navi_location = "" ; String messagelng = "" ; String messagelat = "" ;
try {
tag = detail_infoJson.get("tag").toString();
System.out.println("tag:" + tag);
navi_location = detail_infoJson.get("navi_location").toString();
JSONObject navi_locationJson = JSON.parseObject(navi_location);
messagelng = navi_locationJson.get("lng").toString();
System.out.println("messagelng:" + messagelng);
messagelat = navi_locationJson.get("lat").toString();
System.out.println("messagelat:" + messagelat);
} catch (Exception e) {
System.err.println("detail_infoJson Inner part tag、lng、lat non-existent ");
}
}
边栏推荐
- ref 关键字的用法
- 利用 Fastjson json (简单粗暴版)
- sql 字段类型转换
- Cyclic multi-Variate Function for Self-Supervised Image Denoising by Disentangling Noise from Image
- js常用utils封装
- MySQL learning notes (1) -- variables
- Technology Summit 58 Liu Yuan in the same city was invited to attend qecon 2022 global software quality & effectiveness conference
- New system installation mysql+sqlyog
- 换行问题双保险
- asp.net 的经验
猜你喜欢

Rename file with command line

2022 preparation for autumn recruitment 10W word interview sketch PDF version, with operating system and computer network interview questions

web UI 自动化测试:Selenium 语法详解 史上最全

Kinect2 for Unity3D——AvatarDemo学习

Performance analysis of continuous time system (1) - performance index and first and second order analysis of control system

Introduction to assembly language (1)

MySQL learning notes (1) -- variables

Nacos的基本使用(1)——入门

The go zero singleton service uses generics to simplify the registration of handler routes

Unity显示Kinect捕获的镜头
随机推荐
There is a problem with the time zone when the idea connects to the database. The server returns invalid timezone is red Need to set ‘serverTimezone‘ property.
Using MATLAB to generate graphics for journals and conferences - plot
2022 Ningde Vocational College Teachers' practical teaching ability improvement training - network construction and management
Unity learning notes (realize the conveyor belt)
kettle 分列、合并记录
v-if,v-else,v-for
How to break the team with automated testing
Unity学习笔记——物体移动六种常见函数
Win10 tips (1) -- transfer desktop location
MySQL学习笔记(2)——存储过程与存储函数
101. (cesium chapter) cesium particle system - snow
Kinect for unity3d - backgroundremovaldemo learning
JS common utils encapsulation
Unity shows Kinect captured shots
asp. Net experience
搭建阿里云+typora+Picgo图床错误分析
[Luogu p4183] cow at large P (graph theory) (tree array)
Analysis of Eureka server
连续时间系统的性能分析(1)-控制系统性能指标及一二阶分析
Automatic testing of Web UI: Selenium syntax explanation is the most complete in the history