【问题标题】:Problem with accentuation in return json Rest c #返回 json Rest c # 中的重音问题
【发布时间】:2019-03-16 02:18:03
【问题描述】:

我正在使用 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;
}

谢谢!

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 2014-01-01
  • 1970-01-01
  • 2012-11-29
  • 2020-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多