Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json parse failed #540

Closed
vypivshiy opened this issue Sep 2, 2023 · 1 comment
Closed

json parse failed #540

vypivshiy opened this issue Sep 2, 2023 · 1 comment
Labels

Comments

@vypivshiy
Copy link

vypivshiy commented Sep 2, 2023

Description

Hello! I used your library to make a telegram bot, but the response from the getMe method is parsed with an error.

System

OS: Linux Mint 21.2 x86_64
Kernel: 5.15.0-79-generic
CPU: Intel i5-10400F (12) @ 4.300GHz
Compiler: gfortran 11.4.0

Libraries used

Reproduction

without http_client

program main
  use json_module, only: json_file
  implicit none
  
  type(json_file)                 :: json
  character(:), allocatable  :: jsn_string 
  
  jsn_string = '{"ok":true,"result":{"id":12345678,"is_bot":true,' // &
             '"first_name":"pavel","username":"durov",' // &
             '"can_join_groups":true,"can_read_all_group_messages":false,' // &
             '"supports_inline_queries":false}}'
  call json%initialize()
  call json%deserialize(jsn_string)
  print*, json%failed()  ! T
end program

with http_client

program main
  use json_module, only: json_file
  use http, only : request, response_type, HTTP_POST, pair_type
  implicit none
  
  character(:), allocatable  :: TOKEN
  character(:), allocatable  :: api_url
  character(:), allocatable  :: payload
  type(json_file)                 :: json
  
  ! http variables
  type(pair_type), allocatable          :: req_header(:)
  type(response_type)                   :: response
  
  ! telegram bot valid token variable
  TOKEN = "TELEGRAM_BOT_TOKEN"
  
  ! prepare request
  payload = "{}"
  api_url = "https://api.telegram.org/bot"//TOKEN//"/getMe"
  req_header = [pair_type('Content-Type', 'application/json')]

  ! send request
  response = request(api_url, method=HTTP_POST, data=payload, header=req_header)
  
  call json%initialize()
  call json%deserialize(response%content)
  print*, json%failed()  ! T
end program
@jacobwilliams
Copy link
Owner

The first one works fine for me. What compiler/platform are you using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants