【问题标题】:get value from a JSONObject从 JSONObject 获取值
【发布时间】:2015-07-28 16:08:15
【问题描述】:

我有一个 JSONObject。

{
  "_shards":{
      "total":251,
      "failed":0,
      "successful":251
   },
   "hits":{
      "hits":[

      ],
      "total":7775532,
      "max_score":0
   },
   "took":517,
   "timed_out":false,
   "facets":{
      "terms":{
         "total":2287,
         "other":0,
         "terms":[
            {
               "count":2268,
               "term":"contact"
            },
            {
               "count":19,
               "term":""
            }
         ],
         "_type":"terms",
         "missing":424
      }
   }
}

我想得到 hits.total 的值,这里是 7775532。 我怎么能得到那个?有什么功能可以提供帮助吗?我正在使用 Java

【问题讨论】:

标签: java parsing jsonobject


【解决方案1】:
jsonObject.getJSONObject("hits").get("total")

【讨论】:

  • 如果是 List 怎么办??
  • 我希望结果为字符串
  • 什么列表?如果要将结果作为字符串,请使用 getString("total")
猜你喜欢
  • 2018-12-09
  • 1970-01-01
  • 2013-02-19
  • 2019-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-19
  • 1970-01-01
相关资源
最近更新 更多