首页 > 解决方案 > Newtonsoft.Json 在 RestEase 中抛出异常

问题描述

我遇到了这样的例外

JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 1, position 1.

我正在使用带有此类界面的RestEase( https://github.com/canton7/RestEase )

public interface ISomeApi
{
    [Get("{version}/data/count")]
    Task<SomeResult> GetCount(
        [Path] string version,
        [Query("metaType")] string metaType,
        [Query("query", QuerySerializationMethod.Serialized)] QueryParams queryParams);
}

我的查询参数模型

public class QueryParams
{
    [JsonProperty("foo")]
    public string Foo { get; set; }

    [JsonProperty("bar")]
    public string Bar{ get; set; }

    [JsonProperty("bass")]
    public string Bass{ get; set; }

    [JsonProperty("boom")]
    public string Boom{ get; set; }
}

为什么我会得到这个异常?做错了什么?

我试图避免使用QueryParams并且只是string在我传递的地方使用了已经转换为字符串表示的 json 模型,但得到了相同的异常。我也尝试转义 json 特定符号,但没有帮助。

标签: apiasp.net-corejson.netresteasy

解决方案


推荐阅读