java - JSONObject["platformTypeCode"] 未找到
问题描述
当我尝试从 JSONArray 获取 JSONObject 时,出现以下错误:
JSONObject["platformTypeCode"] 未找到,问题是我需要 platformTypeCode 的值
我的代码如下:
String value = null;
JSONArray packagingList = (packagingInformationModule.has("packaging")) ? packagingInformationModule.getJSONArray("packaging") : null;
if (packagingList!=null) {
int i=0;
while(i<packagingList.length()) {
JSONObject platform = ((JSONObject)packagingList.get(i));
JSONObject platformTypeCode = platform.getJSONObject("platformTypeCode");
value = platformTypeCode.getString("value");
i++;
}
}
我的 Json 如下:
packagingInformationModule": {
"packaging": [
{
"packagingTypeCode": {
"value": "AM"
},
"platformTypeCode": {
"value": "48"
},
"packagingMaterial": [
{
"packagingMaterialTypeCode": {
"value": "FIBRE_BURLAP"
},
"packagingMaterialCompositionQuantity": [
{
"value": 2,
"measurementUnitCode": "KGM"
}
]
}
]
}
]
}
我找不到问题所在,因为当我使用另一个具有相同结构的 Json 进行测试时它正在工作......
解决方案
推荐阅读
- javascript - 处理 AWS lambda 上的事件返回
- react-native - 在 React Native 中,通过键盘和快速输入按钮更新 TextInput 的值
- ssh - 期望脚本登录(ssh)并运行命令,密码取决于环境
- android-studio - 你如何在 Kotlin (android studio) 中 ping
- pandas - 如何在由分区分隔的地图上绘制散点图?
- r - 为多行 ggplot 创建图例
- php - JSON:按 ID 获取项目
- javascript - 是否有等效于 Python 的 getattr() 函数的 Javascript?
- apache-kafka - Kafka Connect:如何将自定义连接器 (SMT) 添加到现有的 Kafka Connect docker 安装中?
- firebase - Cloud Firestore:获取集合中的文档数