Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

java - How can I get a value from a dotted key in Gson?

My goal is to be able to fetch values from a JsonObject using a key, such as example.path.to.string. If you used this key, you should be able to fetch the string value from this:

{
    "example": {
        "path": {
            "to": {
                "string": "Hello world!"
            }
        }
    }
}

Ideally, I would be able to use something like example.getAsJsonObject().get("example.path.to.string").getAsString(); to get this value. However, I have had no luck with it.

I have also seen this question, but it has no explanation and is hard to understand.

How would I go about this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...