exten recursive finding

This commit is contained in:
ccppi 2024-07-04 14:02:46 +02:00
parent 42bd90fb7b
commit d4a3bf6f44
2 changed files with 21 additions and 13 deletions

BIN
main

Binary file not shown.

View File

@ -10,24 +10,32 @@ var client = newHttpClient()
var html: string
#var node: XmlNode
proc do_another_loop( node : JsonNode, level : int, searchString : string = "") =
proc do_another_loop( node : JsonNode, level : int, searchString : string = "",path :string = "H") =
if node.len() > 0:
for a in node.keys:
if node.kind == JObject:
#for i in 0 .. level:
if searchString == "" or contains($node[a],searchString):
stdout.write ">"
stdout.write a
if searchString == "" or a.contains(searchString):
#for x in 0..level:
# stdout.write " "
stdout.write "|", path & "-" & a
if node[a].kind == JObject:
do_another_loop(node[a],level+1,searchString)
stdout.write("\n")
do_another_loop(node[a],level+1,searchString,path & "-" & a)
else:
if searchString == "" or contains($node[a],searchString):
stdout.write " [", node[a].kind, "]\n"
if searchString == "" or a.contains(searchString):
stdout.write " [", node[a].kind, "]"
stdout.write("\n")
if node[a].kind == JArray:
if searchString == "" or contains($node[a],searchString):
echo node[a]
else:
echo "yyyyyyyy"
if searchString == "" or a.contains(searchString):
echo "Array Elements: ", node[a].getElems()
echo "Array Length", node[a].len()
echo "WWWWWWWWWWWWWWW"
for b in node[a]:
echo b
do_another_loop(b,level,searchString,path & "-" & a)
#stdout.write "\n"
else:
echo "\n--------"
@ -60,7 +68,7 @@ try:
#echo "JSON Node:", jsonNode
#echo "node fields: ",jsonNode["props"]["pageProps"]["pageTitle"].getStr()
let field = jsonNode.getFields()
do_another_loop(jsonNode,0,"resultitems")
do_another_loop(jsonNode,0,searchString = "resultItems")
#echo "resultitem", jsonNode["resultItems"]
# for a in jsonNode.keys: