From ff8c80ceed52ba6a3254e4abee9640c5a636cc81 Mon Sep 17 00:00:00 2001 From: Reset Reboot Date: Tue, 8 Sep 2015 11:31:06 +0200 Subject: [PATCH] Now we support more complex JSON structures, but we need refactoring --- src/jsoninspector.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/jsoninspector.py b/src/jsoninspector.py index 3eec458..ecce62c 100644 --- a/src/jsoninspector.py +++ b/src/jsoninspector.py @@ -217,6 +217,26 @@ class LogicObject(object): # los nodos, añadidos como hijos de este self._loadTreeRec(treestore, self.json[key_val], parent_node) + elif type(self.json[key_val]) is list: + count = 0 + # Añadimos el nodo, y obtenemos la referencia + parent_node = treestore.append(None, + [str(key_val), + "", ""]) + for elem in self.json[key_val]: + if type(elem) is dict: + another_node = treestore.append(parent_node, + [unicode(key_val) + u"[" + unicode(count) + u"]", + "", unicode(type(elem))]) + self._loadTreeRec(treestore, elem, another_node) + + else: + treestore.append(parent_node, [unicode(key_val) + u"[" + unicode(count) + u"]", + unicode(elem), + unicode(type(elem))]) + + count += 1 + else: # Tenemos un nodo hoja, obtenemos el valor y el tipo y lo @@ -242,6 +262,26 @@ class LogicObject(object): # los nodos, añadidos como hijos de este self._loadTreeRec(treestore, elems[key_val], new_parent_node) + elif type(elems[key_val]) is list: + count = 0 + # Añadimos el nodo, y obtenemos la referencia + new_parent_node = treestore.append(parent_node, + [str(key_val), + "", unicode(type(elem))]) + for elem in elems[key_val]: + if type(elem) is dict: + another_node = treestore.append(new_parent_node, + [unicode(key_val) + u"[" + unicode(count) + u"]", + "", ""]) + self._loadTreeRec(treestore, elem, another_node) + + else: + treestore.append(new_parent_node, [unicode(key_val) + u"[" + unicode(count) + u"]", + unicode(elem), + unicode(type(elem))]) + + count += 1 + else: # Tenemos un nodo hoja, obtenemos el valor y el tipo y lo