java - 从 JSON 字符串获取内容

标签 java android json

我目前正在开发一个具有 Web 后端的 Android 应用程序。我可以收到如下所示的 JSON 文件:

[{"Latitude":"53.4041999","lontitude":"-6.377542"}]

我试图弄清楚如何从 JSON 文件中获取两个坐标并将它们用于映射位置。有谁知道如何从 JSON 文件中获取两个坐标作为 double 吗?

最佳答案

JSONObject jObject = new JSONObject(response);
double lat = jObject.getDouble("Latitude");
double lng = jObject.getDouble("lontitude");

您需要做的是创建 JSONObject 并使用 getDouble(name); 获取双值

编辑:创建 JSONArray(请参阅下面的 @Glenn.nz 注释)或仅执行 JSONObject jObject = new JSONObject(response.substring(1, response.lenth()-1));

关于java - 从 JSON 字符串获取内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8333072/

相关文章:

Android:onConfigurationChanged() 没有调用 Orientation 的改变

android - 从 firebase 数据库读取数据失败

java - Android : java. lang.String无法转换为JSONArray

java - 在loop/try/catch java中使用外部变量

java - 不同类型的 ArrayList 的总和

java - 正则表达式从url中提取字符串

Java,通过 SSL 连接时出错(远程主机在握手期间关闭连接)

sql - 如何在 Postgres 中加入 jsonb 数组元素?

Java Arraylist 已满但不更新?

java.lang.UnsupportedOperationException 但没有 Arrays.asList()