是否可以使用Java中的org.json解析JSON文件?

时间:2011-03-23 22:29:41

标签: java json

例如如何解析它?

{
    "392bc124":        {
            "ts":        {
                    "value":        "File content"
            },
            "type":        "File content",
            "sn":        "File content"
    },
    "07dba83e":        {
            "ts":        {
                    "value":        "File content"
            },
            "type":        "File content",
            "sn":        "File content"
    },
    "a24faa33":        {
            "ts":        {
                    "value":        "File content"
            },
            "type":        "File content",
            "sn":        "File content"
    }
}

我知道它只适用于一个

{
    "devices" : [
        {
            "name"  : "07dba83e"
            "sn"    : "c8abddf44e49986ff2cd03be6fd2b1fc",
            "type"  : "output",
            "value" : "100"
        },
        {
            "name"  : "392bc124"
            "sn"    : "644f2821b26a7d6c93720b26c5044b40",
            "type"  : "input",
            "value" : "12"
        },
        {
            "name"  : "a24faa33"
            "sn"    : "2893a640fd1b6102c84f035c42ee4257",
            "type"  : "dimmer",
            "value" : "0"
        }
    ]
}

如果我不知道名字(“392bc124”)怎么能得到“392bc124”json对象?在第二个样本我有一个数组,它没关系,但我不知道,有没有办法解析第一个?

1 个答案:

答案 0 :(得分:1)

据推测,您可以使用getNameskeys