c# - Xamarin C# restsharp 解析嵌套的 json 响应
问题描述
我在解析来自 API 的嵌套 JSON 响应时遇到了一些问题。
API 返回一个数组,其中包含一个对象数组。我面临的问题是数组中对象之前每个数组中包含的 int 值(请参阅附加的示例 JSON 片段)。
我目前已经设置了反序列化类型和对象,这看起来很好,但是,当 restsharp 无法将 INT 值反序列化为我的反序列化类型时,就会出现问题。
杰森
[
[
1064,
{
"trx_id": "",
"block": 0,
"trx_in_block": 0,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "",
"op": [
"vote",
{
"voter": "user1",
"author": "user2",
"permlink": "UUID",
"weight": 0
}
]
}
]
]
请求
var response = await restClient.Execute<List<List<Models.Responses.AccountHistory.Transaction>>>(request);
事务.CS
public class Transaction
{
public string trx_id { get; set; }
public long block { get; set; }
public long trx_in_block { get; set; }
public long op_in_trx { get; set; }
public long virtual_op { get; set; }
//Etc..
}
我正在尝试反序列化嵌套的事务数组,int 值不是我有任何实际用途的东西。我正在寻找一种忽略整数并仅解析对象的方法。
错误
未处理的异常:Newtonsoft.Json.JsonSerializationException:将值 0 转换为类型“Models.Responses.AccountHistory.Transaction”时出错。路径“[0][0]”,第 1 行,位置 3。发生
解决方案
您可以为客户端编写自己的自定义反序列RestSharp
化程序。
然后需要在客户端实例化时对其进行设置。
推荐阅读
- android - 如何暂停 ListIterator
- java - 如何获取 Quantity 字段的项目数并计算 TotalTax()?
- typescript - 即使类型不匹配,打字稿也不会出错
- mysql - AWS Django Elastic Beanstalk 迁移错误
- three.js - 是否可以将立方体环境贴图围绕 Y 轴旋转 180 度?
- git - 在将发布分支合并回开发之前将开发合并到发布分支中吗?
- memory-management - 固定分区会受到外部碎片的影响吗?
- ruby-on-rails - Rails 控制台:使用现有记录创建新记录
- r - ggplot 用于存储在 3D 数组中的对象
- mininet - 使用 Ryu 控制器在自定义 mininet 拓扑中生成流量并测量 qos 参数