Json 中的重音或特殊字符问题 (Abap)

Issue with accents or Special characters in Json (Abap)

我正在使用来自 abap 的 HTTP 服务。 服务 returns 我 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( ).

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

中可能缺少字符集

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

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