java 从 JSONObject 获取值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31681705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 18:59:11  来源:igfitidea点击:

get value from a JSONObject

javaparsingjsonobject

提问by Aishwarya Garg

I have a JSONObject.

我有一个 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
      }
   }
}

I want to get the value of hits.total which here is 7775532. How can I get that ? Is there some function that can help ? I am using Java

我想获得 hits.total 的值,这里是 7775532。我怎样才能得到它?是否有一些功能可以提供帮助?我正在使用 Java

回答by cahen

jsonObject.getJSONObject("hits").get("total")