使用解碼例如用ContainerFactory通過時,得到以下輸出:JSON-簡單ContainerFactory通過
[{DeviceType=foo, DeviceName=foo1, IPAddress=192.168.1.1, UserName=admin, Password=pw}, {DeviceType=foo, DeviceName=foo2, IPAddress=192.168.1.2, UserName=admin, Password=pw}]
這些是當entry.getValue()被調用所輸出的條目。
如何從這些對象中獲取數據?
例如,我將如何獲取DeviceName的值。
Map obj = (Map)parser.parse(new FileReader("example.yml"),containerFactory);
Iterator iter = obj.entrySet().iterator();
//Iterator iterInner = new Iterator();
while(iter.hasNext()){
Map.Entry entry = (Map.Entry)iter.next();
System.out.println(entry.getValue());
}
//System.out.println("==toJSONString()==");
//System.out.println(JSONValue.toJSONString(json));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch(ParseException pe){
System.out.println(pe);
}
Ahhhh ...好主意!輸出是類java.lang.String。在鍵值對的第一個parser.parse語句中有沒有辦法? – bentaisan 2012-02-15 00:37:22