json_get_array Subroutine

private subroutine json_get_array(json, me, array_callback)

This routine calls the user-supplied json_array_callback_func subroutine for each element in the array.


Type IntentOptional AttributesName
class(json_core), intent(inout) :: json
type(json_value), intent(in), pointer:: me
procedure(json_array_callback_func) :: array_callback


Source Code

Source Code

    subroutine json_get_array(json, me, array_callback)

    implicit none

    class(json_core),intent(inout)      :: json
    type(json_value),pointer,intent(in) :: me
    procedure(json_array_callback_func) :: array_callback

    type(json_value),pointer :: element !! temp variable for getting elements
    integer(IK) :: i      !! counter
    integer(IK) :: count  !! number of elements in the array

    if ( json%exception_thrown ) return


    select case (me%var_type)
    case (json_array)
        count = json%count(me)
        element => me%children
        do i = 1, count ! callback for each child
            if (.not. associated(element)) then
                call json%throw_exception('Error in json_get_array: '//&
                                          'Malformed JSON linked list')
            end if
            call array_callback(json, element, i, count)
            if (json%exception_thrown) exit
            element => element%next
        end do
    case default

        call json%throw_exception('Error in json_get_array:'//&
                                  ' Resolved value is not an array ')

    end select

    if (associated(element)) nullify(element)

    end subroutine json_get_array