Just starting out? Need help? Post your questions and find answers here.
collectordave
Addict
Posts: 1309 Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal
Post
by collectordave » Wed Aug 21, 2019 4:36 pm
I am attempting to look for a particular key in a JSON by using a repeat loop as below:-
Code: Select all
Repeat
If JSONType(json) = #PB_JSON_Object
If ExamineJSONMembers(json)
While NextJSONMember(json)
If JSONMemberKey(json) = "Key to look for"
Quit = #True
EndIf
NextJson = JSONMemberValue(json)
json = NextJson
Wend
EndIf
EndIf
Until Quit = #True
It allways fails on
While NextJSONMember(json)
Not a clue where I am going wrong
CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
spikey
Enthusiast
Posts: 586 Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom
Post
by spikey » Wed Aug 21, 2019 5:31 pm
You're overriding the tree structures position and pointing it to something else with these lines:-
Code: Select all
NextJson = JSONMemberValue(json)
json = NextJson
At a guess JSONMember <> JSONMemberValue; there is no NextJSONMember to find when the loop iterates and the function call fails.
kenmo
Addict
Posts: 1967 Joined: Tue Dec 23, 2003 3:54 am
Post
by kenmo » Wed Aug 21, 2019 7:01 pm
Yes, you start examining a JSON object, then after 1 loop you change to its first child (which might not be an Object type!) and try to CONTINUE the search on this different node. It doesn't seem written correctly.
Do you have an example of the JSON you're searching?
Are you trying to search just one level "deep" or the entire JSON tree... if the entire tree, then a recursive procedure is probably best. Easy to implement.
collectordave
Addict
Posts: 1309 Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal
Post
by collectordave » Thu Aug 22, 2019 7:48 am
Gave up on repeat loop using recursive code here
viewtopic.php?f=13&t=73443
Still one more little problem with synbols they have used @ for attributes I am attempting to extract with extractjsonarray.
Thanks all
CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.