Alternate version of json_get_alloc_string_vec where input is the path.
This is an alternate version of json_get_string_vec_by_path. This one returns an allocatable length character (where the string length is the maximum length of any element in the array). It also returns an integer array of the actual sizes of the strings in the JSON structure.
An alternative to using this routine is to use json_get_array with a callback function that gets the string from each element and populates a user-defined string type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
character(kind=CK,len=*), | intent(in) | :: | path | |||
character(kind=CK,len=:), | intent(out), | dimension(:), allocatable | :: | vec | ||
integer(kind=IK), | intent(out), | dimension(:), allocatable | :: | ilen | the actual length of each character string in the array |
|
logical(kind=LK), | intent(out), | optional | :: | found |
subroutine json_get_alloc_string_vec_by_path(json, me, path, vec, ilen, found)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer,intent(in) :: me
character(kind=CK,len=*),intent(in) :: path
character(kind=CK,len=:),dimension(:),allocatable,intent(out) :: vec
integer(IK),dimension(:),allocatable,intent(out) :: ilen !! the actual length
!! of each character
!! string in the array
logical(LK),intent(out),optional :: found
type(json_value),pointer :: p
call json%get(me, path, p, found)
if (present(found)) then
if (.not. found) return
else
if (json%exception_thrown) return
end if
call json%get(p, vec, ilen)
if (present(found) .and. json%exception_thrown) then
call json%clear_exceptions()
found = .false.
end if
end subroutine json_get_alloc_string_vec_by_path