abap 多层jason 解析

FUNCTION zfunc_gettoken.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  EXPORTING
*"     VALUE(TOKEN) TYPE  STRING
*"----------------------------------------------------------------------

  DATA:lv_abap        TYPE REF TO cl_abap_conv_in_ce,
       lc_url         TYPE string,
       ev_resp_code   TYPE i,
       ev_resp_reason TYPE string,
       lo_http_client TYPE REF TO if_http_client,
       lv_results     TYPE string.

  TYPES: BEGIN OF ty_header,
           app_id       TYPE string,
           access_token TYPE string,
           expires_in   TYPE string,
         END OF ty_header.

  TYPES: BEGIN OF ty_token,
           token TYPE ty_header,
         END OF ty_token.

  TYPES: BEGIN OF ty_body,
           body TYPE ty_token,
         END OF ty_body.
  DATA:ls_data TYPE ty_body.

  lc_url = 'URL'.
  cl_http_client=>create_by_url(
      EXPORTING
        url    = lc_url
      IMPORTING
        client = lo_http_client
      EXCEPTIONS
        argument_not_found = 1
        plugin_not_active = 2
        internal_error    = 3
        OTHERS            = 4 ).
  IF sy-subrc <> 0.
    RAISE create_by_url_failed.
  ENDIF.

  lo_http_client->request->set_method( if_http_request=>co_request_method_get ).

* Sending the request
  CALL METHOD lo_http_client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2.

* Receiving the response
  CALL METHOD lo_http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3.
  IF sy-subrc EQ 0.

    lv_results = lo_http_client->response->get_cdata( ).

*    lo_http_client->response->get_status(
*      IMPORTING
*        code   = ev_resp_code
*        reason = ev_resp_reason
*    ).
  ENDIF.

  IF lv_results <> ''.
    CALL METHOD /ui2/cl_json=>deserialize
      EXPORTING
        json = lv_results
      CHANGING
        data = ls_data.
    token = ls_data-body-token-access_token.
  ENDIF.
ENDFUNCTION.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ChampaignWolf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值