Get an integer value from a json_value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | intent(in), | pointer | :: | me | ||
integer(kind=IK), | intent(out) | :: | value | the integer value |
subroutine json_get_integer(json, me, value)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer,intent(in) :: me
integer(IK),intent(out) :: value !! the integer value
logical(LK) :: status_ok !! for [[string_to_integer]]
value = 0_IK
if ( json%exception_thrown ) return
if (me%var_type == json_integer) then
value = me%int_value
else
if (json%strict_type_checking) then
call json%throw_exception('Error in json_get_integer:'//&
' Unable to resolve value to integer: '//me%name)
else
!type conversions
select case(me%var_type)
case (json_double)
value = int(me%dbl_value)
case (json_logical)
if (me%log_value) then
value = 1
else
value = 0
end if
case (json_string)
call string_to_integer(me%str_value,value,status_ok)
if (.not. status_ok) then
value = 0_IK
call json%throw_exception('Error in json_get_integer:'//&
' Unable to convert string value to integer: me.'//&
me%name//' = '//trim(me%str_value))
end if
case default
call json%throw_exception('Error in json_get_integer:'//&
' Unable to resolve value to integer: '//me%name)
end select
end if
end if
end subroutine json_get_integer