@@ -9542,58 +9542,51 @@ end subroutine json_get_array
9542
9542
! This routine calls the user-specified [[json_traverse_callback_func]]
9543
9543
! for each element of the structure.
9544
9544
9545
- subroutine json_traverse (json ,p ,traverse_callback )
9545
+ recursive subroutine json_traverse (json ,p ,traverse_callback )
9546
9546
9547
9547
implicit none
9548
9548
9549
9549
class(json_core),intent (inout ) :: json
9550
9550
type (json_value),pointer ,intent (in ) :: p
9551
9551
procedure (json_traverse_callback_func) :: traverse_callback
9552
9552
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
9566
9556
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
9570
9558
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
9574
9560
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.
9593
9562
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
9594
9586
end if
9587
+ nullify(element)
9595
9588
9596
- end subroutine traverse
9589
+ end if
9597
9590
9598
9591
end subroutine json_traverse
9599
9592
! *****************************************************************************************
0 commit comments