【问题标题】:How to get key value from JSON Object having nested object如何从具有嵌套对象的 JSON 对象中获取键值
【发布时间】:2015-08-27 11:53:14
【问题描述】:

我想在Java中获取message属性的值:

{ "responseStatus": { "message": "Success" } }

我这样做了:

lJsonObj.getString("??")

【问题讨论】:

标签: getjson


【解决方案1】:

你可以用这个得到一个嵌套的 json 对象:

JSONObject nestedJsonObject = rootJsonObject.getJSONObject("responseStatus");

你可以从一个 json 对象中得到一个字符串:

String message = nestedJsonObject.getString("message");

【讨论】:

  • 好的答案解释并提供代码。考虑更新您的答案,以包含有关此代码如何工作以及为什么它是最佳选择的说明。
  • 我想使用 slurper 解析。我从变量传递 json Xpath 的地方。比如 def JsonXpath = 'error.errorDetails.errorText' slurper = new JsonSlurper() json = slurper.parseText(responseJsonGP) log.info "json ####" +json resValue = json.(aGlobalProperties[i].toObject)
猜你喜欢
  • 2018-04-14
  • 2016-10-31
  • 2019-07-08
  • 2020-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-18
  • 1970-01-01
相关资源
最近更新 更多