This commit is contained in:
ccppi 2024-07-09 09:56:36 +02:00
parent d45b21d134
commit f849af778d
2 changed files with 15 additions and 35 deletions

BIN
main

Binary file not shown.

View File

@ -39,32 +39,19 @@ proc dbg_al(level : int)=
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) =
if searchString == "" or node.contains(searchString):
dbg_dl(level)
stdout.write path & "-" & key
if node.kind == JObject:
if searchString == "" or node.contains(searchString):
stdout.write("\n")
dbg_dl(level)
echo "childs: "
for y in node.keys:
if searchString == "" or path.contains(searchString):
dbg_dl(level)
stdout.write path & "-" & y," [", node[y].kind,"] \n"
main_loop(node[y],level+1,searchString,path & "-" & key)
stdout.write path & "-" & key & "-" & y," [", node[y].kind,"] {" ,key,"}","\n"
main_loop(node[y],level+1,searchString,path & "-" & key & "-" & y)
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:
if searchString == "" or path.contains(searchString) or key.contains(searchString):
dbg_al(level)
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") =
@ -72,6 +59,7 @@ proc main_loop[T]( node : T , level : int, searchString : string = "",path :stri
if node.kind == JObject:
var elem = node.getElems()
for b in node.pairs:
if searchString == "" or path.contains(searchString) or b.key.contains(searchString):
dbg_ml(level)
echo "element: ",b, " path: ",path
for a in node.keys:
@ -111,19 +99,11 @@ try:
let jsonNode = parseJson(jsonString)
#echo "jsonString: ",jsonString
#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"]
# for a in jsonNode.keys:
# echo a
# if jsonNode[a].len() > 0:
# for b in jsonNode[a].keys:
# echo ">>>"
# main_loop(jsonNode[a][b])
# else:
# echo "---------------"
let field = jsonNode.getFields()
main_loop(jsonNode,0,searchString = "Title")
#-props-pageProps-initialResultData-resultItems
echo "node fields: ",jsonNode["props"]["pageProps"]["initialResultData"]["resultItems"][0]["Title"]
finally:
client.close()