<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.72</version>
</dependency>
String jsonStr = “{“lng”:120.413354,“lat”:31.298914}”
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
public class JSONDataProcessing {
public static void main(String[] args) {
String jsonStr = "{\"lng\":120.413354,\"lat\":31.298914}";
JSONObject jsonObject = JSON.parseObject(jsonStr);
// 经度纬度对应的值
System.out.println("经度:" + jsonObject.get("lng") + "纬度:" + jsonObject.get("lat"));
}
}
String jsonStr = “[[{“lng”:120.405054,“lat”:31.288329},{“lng”:120.405215,“lat”:31.287913}]]”;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
public class JSONDataProcessing {
public static void main(String[] args) {
String jsonStr = "[[{\"lng\":120.405054,\"lat\":31.288329},{\"lng\":120.405215,\"lat\":31.287913}]]";
// 先转jsonArray
JSONArray jsonArray = JSONArray.parseArray(jsonStr);
for (Object o : jsonArray) {
List<JSONObject> jsonObjectList = (List) o;
jsonObjectList.forEach(item -> {
// 单个经纬度json
System.out.println(item);
// 经度纬度对应的值
System.out.println("经度:" + item.get("lng") + "纬度:" + item.get("lat"));
});
}
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/172475.html原文链接:https://javaforall.cn