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 |
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
value = 0
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 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 default
call json%throw_exception('Error in get_integer:'//&
' Unable to resolve value to integer: '//me%name)
end select
end if
end if
end subroutine json_get_integer