简体   繁体   English

我如何解析 json 响应,以便我只能使用 Java 获取密钥?

[英]How i can get the parse the json response such that i can get only keys with Java?

How can I parse the JSON response such that I can get only randomly generated keys from JSON like this如何解析 JSON 响应,以便我只能像这样从 JSON 中获取随机生成的密钥

  "6e38fad50-39a0-11e9-9511-0242ac110002"

available in JSON?在 JSON 中可用?

Response:回复:

{
    "results": {
        "6e38fd50-39a0-11e9-9511-0242ac110002": {
            "name": "11TAG_WITH_CAPS1",
            "type": "CAMPAIGN"
        },
        "744d29d0-39a2-11e9-8e34-0242ac110004": {
            "name": "121TAG_WITH_CAPS1",
            "type": "CAMPAIGN"
        }
    }

Without using java script不使用java脚本

Using GSON and JSON.使用 GSON 和 JSON。

Your question is not so clear你的问题不是很清楚
But see this sample how to convert the json and iterate in it.但是请参阅此示例如何转换 json 并在其中进行迭代。

 var jsonStr = JSON.parse('{ "results": { "6e38fd50-39a0-11e9-9511-0242ac110002": { "name": "11TAG_WITH_CAPS1", "type": "CAMPAIGN" }, "744d29d0-39a2-11e9-8e34-0242ac110004": { "name": "121TAG_WITH_CAPS1", "type": "CAMPAIGN" } }}'); var results = jsonStr.results; for (result in results){ alert(result); if(result == '6e38fd50-39a0-11e9-9511-0242ac110002'){ alert('found it!'); } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM