2011-03-23 92 views
0

如何解析它?在Java中使用org.json解析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」 JSON對象,如果我不知道名字(「392bc124」)?在第二個示例中,我有一個數組,它可以,但我不知道,有沒有解析第一個的方法?

+0

你試過了嗎?結果是什麼? – Davidann 2011-03-23 22:38:10

回答