@@ -9542,58 +9542,51 @@ end subroutine json_get_array
95429542! This routine calls the user-specified [[json_traverse_callback_func]]
95439543! for each element of the structure.
95449544
9545- subroutine json_traverse (json ,p ,traverse_callback )
9545+ recursive subroutine json_traverse (json ,p ,traverse_callback )
95469546
95479547 implicit none
95489548
95499549 class(json_core),intent (inout ) :: json
95509550 type (json_value),pointer ,intent (in ) :: p
95519551 procedure (json_traverse_callback_func) :: traverse_callback
95529552
9553- logical (LK) :: finished ! ! can be used to stop the process
9554-
9555- if (.not. json% exception_thrown) call traverse(p)
9556-
9557- contains
9558-
9559- recursive subroutine traverse (p )
9560-
9561- ! ! recursive [[json_value]] traversal.
9562-
9563- implicit none
9564-
9565- type (json_value),pointer ,intent (in ) :: p
9553+ type (json_value),pointer :: element ! ! a child element
9554+ integer (IK) :: i ! ! counter
9555+ integer (IK) :: icount ! ! number of children
95669556
9567- type (json_value),pointer :: element ! ! a child element
9568- integer (IK) :: i ! ! counter
9569- integer (IK) :: icount ! ! number of children
9557+ logical (LK) :: finished ! ! can be used to stop the process
95709558
9571- if (json% exception_thrown) return
9572- call traverse_callback(json,p,finished) ! first call for this object
9573- if (finished) return
9559+ if (json% exception_thrown) return
95749560
9575- ! for arrays and objects, have to also call for all children:
9576- if (p% var_type== json_array .or. p% var_type== json_object) then
9577-
9578- icount = json% count (p) ! number of children
9579- if (icount> 0 ) then
9580- element = > p% children ! first one
9581- do i = 1 , icount ! call for each child
9582- if (.not. associated (element)) then
9583- call json% throw_exception(' Error in json_traverse: ' // &
9584- ' Malformed JSON linked list' )
9585- return
9586- end if
9587- call traverse(element)
9588- if (finished .or. json% exception_thrown) exit
9589- element = > element% next
9590- end do
9591- end if
9592- nullify(element)
9561+ ! ! recursive [[json_value]] traversal.
95939562
9563+ if (json% exception_thrown) return
9564+ call traverse_callback(json,p,finished) ! first call for this object
9565+ if (finished) return
9566+
9567+ ! for arrays and objects, have to also call for all children:
9568+ if (p% var_type== json_array .or. p% var_type== json_object) then
9569+
9570+ print * , loc(p), associated (p)
9571+ icount = json% count (p) ! number of children
9572+ print * , icount
9573+ if (icount> 0 ) then
9574+ print * , icount, " >0"
9575+ element = > p% children ! first one
9576+ do i = 1 , icount ! call for each child
9577+ if (.not. associated (element)) then
9578+ call json% throw_exception(' Error in json_traverse: ' // &
9579+ ' Malformed JSON linked list' )
9580+ return
9581+ end if
9582+ call json% traverse(element, traverse_callback)
9583+ if (finished .or. json% exception_thrown) exit
9584+ element = > element% next
9585+ end do
95949586 end if
9587+ nullify(element)
95959588
9596- end subroutine traverse
9589+ end if
95979590
95989591 end subroutine json_traverse
95999592! *****************************************************************************************
0 commit comments