我正在使用 abap 的 HTTP 服务。
该服务返回一个包含以下数据的 json:

{
  "statusCode": 200,
  "message": "éxito",
  "data": [
    {
      "_id": "584e9469df829275019c4a74",
      "nombre": "COCHAMÓ",
      "Útil": "Si",
      "email": "supervisor@demo.com",
      "Sms Número de teléfono": "981363931",
      "Llamar al teléfono": "26944444",
      "Radio de búsquedaPedido Público(Km) 1": 3,
      "Radio de búsquedaPedido Público(Km) 2": 3,
      "Radio de búsquedaPedido Público(Km) 3": 3,
      "Tiempo de Descarga masa(min)": 10,
      "Radio de búsquedaPedido Privado(Km)": 1,
      "Cola de Pedidos(n)": 6,
      "Tiempo de Esperapara Asignar pedidos(Sgds)": 45,
      "Hora de finalización": "21:00"
        }
  ]
}

编码:
 Call method cl_http_client=>create_by_url
     Exporting
      url                = lv_url
     Importing
      client             = Data(lcl_client)
     Exceptions
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      Others             = 4.
     If sy-subrc Ne 0.
      Raise urlexception.
     Else.
      Data(lcl_request) = lcl_client->request.
      lcl_client->request->set_method( if_http_request=>co_request_method_post ).
      lcl_request->set_form_field( name = Parametro1 value = lv_mail ).
      lcl_request->set_form_field( name = Parametro2 value = lv_password ).
      If idcomuna Is Not Initial.
       lv_comunasap = idcomuna.
       lcl_request->set_form_field( name = Parametro3 value = lv_comunasap ).
      Endif.
      If idcomunagc Is Not Initial.
       lv_comunamongo = idcomunagc.
       lcl_request->set_form_field( name = Parametro4 value = lv_comunamongo ).
      Endif.

      cl_http_utility=>set_request_uri(  request = lcl_request
                                            uri  = lv_url ).
      Call method lcl_client->send
       Exceptions
        http_communication_failure = 1
        http_invalid_state         = 2
        http_processing_failed     = 3
        http_invalid_timeout       = 4
        Others                     = 5.
        If sy-subrc Ne 0.
         Raise sendexception.
        Else.
         Call method lcl_client->receive
          Exceptions
           http_communication_failure = 1
           http_invalid_state         = 2
           http_processing_failed     = 3
          Others                      = 4.
          If sy-subrc <> 0.
          Else.
           lcl_client->response->get_status( Importing code = Data(lv_code) reason = Data(lv_reason) ).
           Data(lv_respuesta) = lcl_client->response->get_cdata( ).
  • 最初 json 应该带有口音(西类牙语名称)。
  • é, ú 是奇怪的字符之一,它应该是带重音的字母。
    如何在我的 ABAP 程序中获取带有口音的 json 完整数据?
  • 最佳答案

    无论它在显示器上还是在变量中输出,@Jagger 都是正确的,响应以 UTF-8 返回。当您使用 GET_CDATA (获取字符)时,我认为 SAP 采用响应 header ( charset ) 中给出的显式 Content-Type: text/json;charset=utf-8,因此应该正确转换。如果不是,那么标题中可能缺少字符集。

    因此,如果未给出,则自己进行转换,与任何其他 UTF-8 的转换方式相同:

    首先,使用GET_DATA(不是GET_CDATA)将其读取为字节串,然后使用CL_ABAP_CODEPAGE类的方法CONVERT_FROM(codepage = `utf-8`)将其转换为字符串。

    关于web-services - Json (Abap) 中的重音或特殊字符问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49520376/

    10-11 20:34
    查看更多