我从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( ).
答案 0 :(得分:4)
无论显示器或变量的输出是什么,@ Jagger都是正确的,响应以UTF-8返回。当您使用GET_CDATA(获取字符)时,我认为SAP采用响应头(charset
)中给出的显式Content-Type: text/json;charset=utf-8
,因此应该正确转换它。如果不是,那么标题中可能缺少字符集。
所以,如果没有给出,那么自己进行转换,就像对任何其他UTF-8一样:
首先,使用GET_DATA(不是GET_CDATA)将其作为字节串读取,然后使用CL_ABAP_CODEPAGE类的方法CONVERT_FROM(codepage =`utf-8`)将其转换为字符串。 / p>