sdaf
This commit is contained in:
parent
d45b21d134
commit
f849af778d
40
main.nim
40
main.nim
@ -39,32 +39,19 @@ proc dbg_al(level : int)=
|
|||||||
proc main_loop[T]( node : T , level : int, searchString : string = "",path :string = "H")
|
proc main_loop[T]( node : T , level : int, searchString : string = "",path :string = "H")
|
||||||
|
|
||||||
proc do_loop[T](node: T,level : int, searchString : string = "", path: string = "", key : string) =
|
proc do_loop[T](node: T,level : int, searchString : string = "", path: string = "", key : string) =
|
||||||
if searchString == "" or node.contains(searchString):
|
|
||||||
dbg_dl(level)
|
|
||||||
stdout.write path & "-" & key
|
|
||||||
if node.kind == JObject:
|
if node.kind == JObject:
|
||||||
if searchString == "" or node.contains(searchString):
|
|
||||||
stdout.write("\n")
|
|
||||||
dbg_dl(level)
|
|
||||||
echo "childs: "
|
|
||||||
for y in node.keys:
|
for y in node.keys:
|
||||||
|
if searchString == "" or path.contains(searchString):
|
||||||
dbg_dl(level)
|
dbg_dl(level)
|
||||||
stdout.write path & "-" & y," [", node[y].kind,"] \n"
|
stdout.write path & "-" & key & "-" & y," [", node[y].kind,"] {" ,key,"}","\n"
|
||||||
main_loop(node[y],level+1,searchString,path & "-" & key)
|
main_loop(node[y],level+1,searchString,path & "-" & key & "-" & y)
|
||||||
|
|
||||||
proc do_array_loop(node : JsonNode, level : int, searchString : string = "", path: string = "",key :string = "") =
|
proc do_array_loop(node : JsonNode, level : int, searchString : string = "", path: string = "",key :string = "") =
|
||||||
if searchString == "" or node.contains(searchString):
|
|
||||||
dbg_al(level)
|
|
||||||
echo "Key: ",key
|
|
||||||
#dbg_al(level)
|
|
||||||
#echo "Array Elements: ", node.getElems()
|
|
||||||
dbg_al(level)
|
|
||||||
echo "Array Length", node.len()
|
|
||||||
dbg_al(level)
|
|
||||||
for b in node.getElems:
|
for b in node.getElems:
|
||||||
|
if searchString == "" or path.contains(searchString) or key.contains(searchString):
|
||||||
dbg_al(level)
|
dbg_al(level)
|
||||||
echo "node : ", "array_node_len: ", b.len()," ,subkind: " ,b.kind, "mainkind: ", node.kind
|
echo "node : ", "array_node_len: ", b.len()," ,subkind: " ,b.kind, "mainkind: ", node.kind
|
||||||
main_loop(b,level+1,searchString,path & "-A-" & key)
|
main_loop(b,level+1,searchString,path & key)
|
||||||
|
|
||||||
|
|
||||||
proc main_loop[T]( node : T , level : int, searchString : string = "",path :string = "H") =
|
proc main_loop[T]( node : T , level : int, searchString : string = "",path :string = "H") =
|
||||||
@ -72,6 +59,7 @@ proc main_loop[T]( node : T , level : int, searchString : string = "",path :stri
|
|||||||
if node.kind == JObject:
|
if node.kind == JObject:
|
||||||
var elem = node.getElems()
|
var elem = node.getElems()
|
||||||
for b in node.pairs:
|
for b in node.pairs:
|
||||||
|
if searchString == "" or path.contains(searchString) or b.key.contains(searchString):
|
||||||
dbg_ml(level)
|
dbg_ml(level)
|
||||||
echo "element: ",b, " path: ",path
|
echo "element: ",b, " path: ",path
|
||||||
for a in node.keys:
|
for a in node.keys:
|
||||||
@ -111,19 +99,11 @@ try:
|
|||||||
let jsonNode = parseJson(jsonString)
|
let jsonNode = parseJson(jsonString)
|
||||||
#echo "jsonString: ",jsonString
|
#echo "jsonString: ",jsonString
|
||||||
#echo "JSON Node:", jsonNode
|
#echo "JSON Node:", jsonNode
|
||||||
#echo "node fields: ",jsonNode["props"]["pageProps"]["pageTitle"].getStr()
|
|
||||||
let field = jsonNode.getFields()
|
|
||||||
main_loop(jsonNode,0,searchString = "")
|
|
||||||
|
|
||||||
#echo "resultitem", jsonNode["resultItems"]
|
let field = jsonNode.getFields()
|
||||||
# for a in jsonNode.keys:
|
main_loop(jsonNode,0,searchString = "Title")
|
||||||
# echo a
|
#-props-pageProps-initialResultData-resultItems
|
||||||
# if jsonNode[a].len() > 0:
|
echo "node fields: ",jsonNode["props"]["pageProps"]["initialResultData"]["resultItems"][0]["Title"]
|
||||||
# for b in jsonNode[a].keys:
|
|
||||||
# echo ">>>"
|
|
||||||
# main_loop(jsonNode[a][b])
|
|
||||||
# else:
|
|
||||||
# echo "---------------"
|
|
||||||
finally:
|
finally:
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user