0

Using the decoding example with the containerFactory, I get the following output:

[{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}]

These are the entries that are outputted when entry.getValue() is called.

How do I get the data out from these objects?

For example, how would I get the value of 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);
          }

Aaron
  • 55,518
  • 11
  • 116
  • 132
bentaisan
  • 1,056
  • 3
  • 12
  • 29

2 Answers2

1

Try finding out what classes the values are with System.out.println(entry.getValue().getClass()) (or inspect it in debugger) and the values to actual classes. From the output it looks like List<Map<String, String>> or something.

pingw33n
  • 12,292
  • 2
  • 37
  • 38
  • Ahhhh...good idea! The output is class java.lang.String. Is there a way in the first parser.parse statement to key-value pairs? – bentaisan Feb 15 '12 at 00:37
0
//The innermost data is in a LinkedHashMap
//I hope this snippet helps someone
while(iter.hasNext)
    {
        LinkedList entry = (LinkedList)iter.next();
        LinkedList myList = new LinkedList();
        Map.Entry entry = (Map.Entry)iter.next();
        System.out.println(entry.getValue().getClass());
        myList = (LinkedList) (entry.getValue());
        System.out.println(myList);
        Iterator iterate = myList.iterator();
        while (iterate.hasNext())
        {
            LinkedHashMap entry2 = (LinkedHashMap)iterate.next();
            System.out.println(entry2.get("DeviceName"));

        }

}
bentaisan
  • 1,056
  • 3
  • 12
  • 29