Returns a child in the object or array given the index.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | p | object or array JSON data |
|
integer(kind=IK), | intent(in) | :: | idx | index of the child |
||
type(json_value), | pointer | :: | child | pointer to the child |
subroutine json_value_get_by_index(json, p, idx, child)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer,intent(in) :: p !! object or array JSON data
integer(IK),intent(in) :: idx !! index of the child
type(json_value),pointer :: child !! pointer to the child
integer(IK) :: i
nullify(child)
if (.not. json%exception_thrown) then
if (associated(p%children)) then
child => p%children
do i = 1, idx - 1
if (associated(child%next)) then
child => child%next
else
call json%throw_exception('Error in json_value_get_by_index:'//&
' child%next is not associated.')
nullify(child)
return
end if
end do
else
call json%throw_exception('Error in json_value_get_by_index:'//&
' p%children is not associated.')
end if
end if
end subroutine json_value_get_by_index