0

我正在尝试从 .Net CF 2.0 代码调用 Web api。该 api 运行良好,直接从浏览器调用,行为符合预期。CF代码编译好,但是在debug的时候,上线失败

JSONResponse rp = JsonConvert.DeserializeObject<JSONResponse>(returnString);

JSONResponse 类是:

    public class JSONResponse{
    [JsonProperty(PropertyName = "DbServerInstance")]
    public string dbServerInstance { get; set; }

    [JsonProperty(PropertyName = "DbServerUser")]
    public string dbServerUser { get; set; }

    [JsonProperty(PropertyName = "DbServerPassword")]
    public string dbServerPassword { get; set; }

    [JsonProperty(PropertyName = "DbServerDatabase")]
    public string dbServerDatabase { get; set; }

    [JsonProperty(PropertyName = "UserManualURL")]
    public string userManualURL { get; set; }

    [JsonProperty(PropertyName = "ApplicationName")]
    public string applicationName { get; set; }
}

我得到的错误是: {“无法从程序集'mscorlib,Version = 2.0.0.0,Culture = Neutral,PublicKeyToken = 969DB8053D3322AC'加载类型'System.Runtime.CompilerServices.CompilerGeneratedAttribute'。”} System.Exception {System.TypeLoadException }

我应该将项目升级到 .Net CF 3.5 吗?或者是别的什么?

任何帮助和意见表示赞赏。

编辑:将项目升级到 CF 3.5,我得到了预期的 JSON 字符串

<ArrayOfParameterSetUpdater><ParameterSetUpdater><DbServerDatabase>Py0/Pzw/MgM/Pz8/Rj8=</DbServerDatabase><DbServerInstance>PwlAaWU/cD8/fgo/Pyg/VQ==</DbServerInstance><DbServerPassword>PxUqNj9VO2Y/DV4vP0Z2Cg==</DbServerPassword><DbServerUser>FQEvDTI/QQwSP1I/Pz8/Pw==</DbServerUser><id>1</id></ParameterSetUpdater></ArrayOfParameterSetUpdater>

但现在我收到错误 {“无法将 JSON 数组反序列化为类型 'app.JSONResponse'。”} System.Exception {Newtonsoft.Json.JsonSerializationException}

从我所见,课程是正确的,所以我不明白出了什么问题。

任何帮助和意见表示赞赏。

4

0 回答 0