小编Chi*_*ant的帖子

使用java从动态json中查找键的值

我需要从动态json中获取键的值.
Input-> json Object,String key
Output-> json element(对应键的值)
示例

JsonObject Jmsg =

{
  "id": "1753_CORE1",
  "name": "Gtx cuda Service:1753",
  "shortName": "gt-service-1753",
  "createdDate": "Mar 31, 2015 4:47:10 PM",
  "config": {
    "oauthSecret": [
      {
        "id": 45,
        "config123": {
          "oauthSecret": "P8n2x5Hsst0nFRRB0A",
          "status": "CREATED"
        },
        "SERVER132": "1000"
      },
      {
        "id": 46,
        "config123": {
          "oauthSecret": "P8n2x5Htss0nFRRB0A"
        },
        "SERVER132": "1000"
      }
    ],
    "oauthKey": "154284-service-1753",
    "SERVER": "1000"
  },
  "features": [
    9004,
    9005
  ]
}
Run Code Online (Sandbox Code Playgroud)

和String key ="status";
然后JsonElement Jvalue = jsonGetValueformKey(Jmsg,key);
应该在JsonElement或字符串类型中返回'CREATED'.

if String key ="features";
然后 …

java search json

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×1

json ×1

search ×1