@@ -9530,58 +9530,51 @@ end subroutine json_get_array
9530
9530
! This routine calls the user-specified [[json_traverse_callback_func]]
9531
9531
! for each element of the structure.
9532
9532
9533
- subroutine json_traverse (json ,p ,traverse_callback )
9533
+ recursive subroutine json_traverse (json ,p ,traverse_callback )
9534
9534
9535
9535
implicit none
9536
9536
9537
9537
class(json_core),intent (inout ) :: json
9538
9538
type (json_value),pointer ,intent (in ) :: p
9539
9539
procedure (json_traverse_callback_func) :: traverse_callback
9540
9540
9541
- logical (LK) :: finished ! ! can be used to stop the process
9542
-
9543
- if (.not. json% exception_thrown) call traverse(p)
9544
-
9545
- contains
9546
-
9547
- recursive subroutine traverse (p )
9548
-
9549
- ! ! recursive [[json_value]] traversal.
9550
-
9551
- implicit none
9552
-
9553
- type (json_value),pointer ,intent (in ) :: p
9541
+ type (json_value),pointer :: element ! ! a child element
9542
+ integer (IK) :: i ! ! counter
9543
+ integer (IK) :: icount ! ! number of children
9554
9544
9555
- type (json_value),pointer :: element ! ! a child element
9556
- integer (IK) :: i ! ! counter
9557
- integer (IK) :: icount ! ! number of children
9545
+ logical (LK) :: finished ! ! can be used to stop the process
9558
9546
9559
- if (json% exception_thrown) return
9560
- call traverse_callback(json,p,finished) ! first call for this object
9561
- if (finished) return
9547
+ if (json% exception_thrown) return
9562
9548
9563
- ! for arrays and objects, have to also call for all children:
9564
- if (p% var_type== json_array .or. p% var_type== json_object) then
9565
-
9566
- icount = json% count (p) ! number of children
9567
- if (icount> 0 ) then
9568
- element = > p% children ! first one
9569
- do i = 1 , icount ! call for each child
9570
- if (.not. associated (element)) then
9571
- call json% throw_exception(' Error in json_traverse: ' // &
9572
- ' Malformed JSON linked list' )
9573
- return
9574
- end if
9575
- call traverse(element)
9576
- if (finished .or. json% exception_thrown) exit
9577
- element = > element% next
9578
- end do
9579
- end if
9580
- nullify(element)
9549
+ ! ! recursive [[json_value]] traversal.
9581
9550
9551
+ if (json% exception_thrown) return
9552
+ call traverse_callback(json,p,finished) ! first call for this object
9553
+ if (finished) return
9554
+
9555
+ ! for arrays and objects, have to also call for all children:
9556
+ if (p% var_type== json_array .or. p% var_type== json_object) then
9557
+
9558
+ print * , loc(p), associated (p)
9559
+ icount = json% count (p) ! number of children
9560
+ print * , icount
9561
+ if (icount> 0 ) then
9562
+ print * , icount, " >0"
9563
+ element = > p% children ! first one
9564
+ do i = 1 , icount ! call for each child
9565
+ if (.not. associated (element)) then
9566
+ call json% throw_exception(' Error in json_traverse: ' // &
9567
+ ' Malformed JSON linked list' )
9568
+ return
9569
+ end if
9570
+ call json% traverse(element, traverse_callback)
9571
+ if (finished .or. json% exception_thrown) exit
9572
+ element = > element% next
9573
+ end do
9582
9574
end if
9575
+ nullify(element)
9583
9576
9584
- end subroutine traverse
9577
+ end if
9585
9578
9586
9579
end subroutine json_traverse
9587
9580
! *****************************************************************************************
0 commit comments