返回JSON Rest C中的重音问题

时间:2018-10-11 05:08:14

标签: c# asp.net .net asp.net-mvc web-services

我正在使用RestClient.Execute()方法运行Rest调用,该方法包含带有特殊字符的重音符号的JSON数据。

通过SoapUI进行相同的调用,但返回的字符破损没有得到回报。

我的代码:

public ProviderRestResponse<Response> PostService(ProviderRestRequest request)
{
    var response = new ProviderRestResponse<Response>();

    try
    {

        var client = new RestClient(request.UrlService);

        var restRequest = new RestRequest(Method.POST);

        restRequest.Parameters.Clear();

        var dadosDessao = new
        {
            request.DadosSessao
        };

        restRequest.AddJsonBody(request.Parameters);
        restRequest.AddJsonBody(dadosDessao);

        var restResponse = client.Execute(restRequest);


        if (restResponse.ResponseStatus == ResponseStatus.Error)
        {
            throw new Exception(restResponse.ErrorMessage, restResponse.ErrorException);
        }

        var obj = ((dynamic)JsonConvert.DeserializeObject(restResponse.Content)).Resultado;

        response.Data = JsonConvert.DeserializeObject<Response>(JsonConvert.SerializeObject(obj));

        response.Content = restResponse.Content;

        response.ResponseType = ResponseType.Success;
    }
    catch (Exception ex)
    {
        response.Message = ex.Message;
        response.ResponseType = ResponseType.Error;
    }

    return response;
}

Print JSON Result

谢谢!

1 个答案:

答案 0 :(得分:0)

我不知道您正在使用哪个库,但请检查此响应的编码选项,可能是编码问题。使用UTF-8。