java - 获取 JSON 项目内部的 JSON 项目 Java

标签 java json

所以我有一个如下所示的 JSON 对象:

{
    "accessToken" : "<dont need this>",
    "clientToken" : "<nor this>",
    "selectedProfile" : {
        "id" : "<nope>",
        "name" : "<I need this>",
        "legacy" : true
    },
    "availableProfiles" :
    [
        {
            "id" : "<not this>",
            "name" : "<not this>",
            "legacy" : true
        }
    ]
}

所以我需要的是selectedProfile > name。我能够提取选定的配置文件,我可以重复该过程吗?我应该怎么做才能取回它?

最佳答案

使用javax.json

 JsonReader reader = new JsonReader(yourString);
 JsonObject base = reader.readObject();
 JsonObject profile = base.getJsonObject("selectedProfile");
 String name = profile.getJsonString("name");

然后 name 应该是你想要的对象。

关于java - 获取 JSON 项目内部的 JSON 项目 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34453957/

相关文章:

java - IntelliJ - 无法解析符号 'Arrays'

java - 如何格式化无换行json文件?

android - 执行 JSON 请求时出现内部错误

javascript - Gruntfile.js 中 JSON 文件的动态合并

sql - 使用 FOR JSON 时获取值数组而不是对象数组

c# - 用非法变量字符在C#中反序列化json

Java作业: Print Arrays with stored random numbers in it

java - @Transactional 回滚时抛出 "Transaction not successfully started"

java - Canvas 上的透明 JPanel (VLCJ)

javascript - 使用 Nashorn 遍历数组