java - 如何解析这个带有内层的 json 文件?
问题描述
JSON:
{
"prop":"property",
"inputInfo":{
"sku":"6157068",
"inputText":"iphone"
}
}
代码:
JSONObject inputObject = JSON.parseObject(input);
String prop = (String)inputObject.get("property");
但是如何获取'sku'&'inputText'的内层呢?
我在 Java 中使用阿里巴巴 json 库。
解决方案
我没用过阿里巴巴库,但它没有getJSONObject()
你可以使用的方法inputObject
吗?我以前做过,但我使用了org.json
图书馆。
JSON:
{"circle":{
"radius":255819.07998349078,
"center":{
"lat":00.000000000000000,
"lng":00.000000000000000
}
}
}
爪哇
JSONObject shape = new JSONObject(entity.getJsonLocation());
double latitude = shape.getJSONObject("circle")
.getJSONObject("center")
.getDouble("lat");
double longitude = shape.getJSONObject("circle")
.getJSONObject("center")
.getDouble("lng");
例如,此示例获取 JSON 并创建一个JSONObject shape
. 然后我可以通过调用来获取内部 jsongetJSONObject()
对象shape
。
我希望这可以帮助你。
推荐阅读
- spring-boot - java.util.concurrent.RejectedExecutionException:拒绝命令,因为线程池 queueSize 处于拒绝阈值
- django - 为什么 {{ attribute.label.tag }} 中的“label.tag”在 django 模板中不起作用?我们如何获取模板中列的标签?
- vue.js - 在不更改 URL 的情况下使用 vue-i18n 翻译 WebApp
- ios - UICollectionView 中的缩放 ImageView 不一致
- vb.net - String.Format() - 如何使用包含格式的变量?
- angular - 如何更改 Ionic 4 的 ion-range pin 字体和格式?
- java - 如何提高大型 JTable 的滚动性能?
- java - 多个 Xodus 应用程序访问/共享单个目录
- c# - Moq 对象总是返回 null ,为什么?
- sql-server - 如何创建短期和长期数据库目标