RestSharp反序列化JSON内容(代表一个对象包含字节数组)错误 [英] RestSharp deserialize JSON content(represent an object contains an byte array) error

查看:105
本文介绍了RestSharp反序列化JSON内容(代表一个对象包含字节数组)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户端收到正式的JSON内容 {\ Id\:[1,2,3],\ Size\:56} ,但在反序列化字节数组时遇到错误。

The Client side receives a formal JSON content "{\"Id\":[1,2,3],\"Size\":56}", but get an error in deserialization the byte array.

1以下语句中发生错误

1 Error occurs in the statement below

IRestResponse<key> response = client.Execute<key>(request);

2错误消息是没有为此对象定义无参数构造函数。

2 Error message is "No parameterless constructor defined for this object."

3客户端大小的对象类与服务器端的对象类相同:

3 The object class in client size is the same as it's in server side:

public class key
{
    public byte[] id { get; set; }
    public int Size { set; get; }
}

4我尝试通过JSON格式传递包含字符串和整数的对象

4 I've tried passing object that contains string and integer by JSON format and that's all fine but byte array.

推荐答案

RestSharp的JsonDeserializer无法反序列化数组。代替 byte [] ,使用 List< byte> 。有关更多信息,请参见 https://github.com/restsharp/RestSharp/wiki/Deserialization

JsonDeserializer from RestSharp can not deserialize array. Instead of byte[] use List<byte>. For more information see https://github.com/restsharp/RestSharp/wiki/Deserialization

这篇关于RestSharp反序列化JSON内容(代表一个对象包含字节数组)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆