使用带有 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);
}