【问题标题】:Strange Json deserialize [duplicate]奇怪的Json反序列化[重复]
【发布时间】:2017-08-18 13:51:24
【问题描述】:

我尝试与 RouteXL 建立连接,但在 api 响应中我得到一个可能无效的 json。

他从标签路由发送一个以字符串索引开始的数组。通常我将它转换为一个类(http://json2csharp.com),但是使用这个 json,由于字符串索引,我得到了一个无效的类结构。

在我自己去拆分之前。你们有更好的解决方案吗?

关于,

SirNirido

json:

{ 
    "id": "6VTa8zH8",
    "count":5,
    "feasible":true,
    "route": {
        "0": { "name": "StartLocatie", "arrival":0, "distance":0},
        "1": { "name": "58", "arrival":28, "distance":47.7},
        "2": { "name": "57", "arrival":42, "distance":65.3},
        "3": { "name": "56", "arrival":47, "distance":68.5},
        "4": { "name": "StartLocatie", "arrival":61, "distance":87.1}}}

【问题讨论】:

  • 这是一个有效的 json
  • 尝试将route 部分反序列化为Dictionary<int, Route> 或Dictionary<string, Route>。我确定这在某处是重复的……

标签: c# json


【解决方案1】:

感谢@JonSkeet,它就像一个魅力。

这对谷歌来说很难。但是,如果有人遇到同样的问题,那就是我的新类模式

class Results
    {
        public string id { get; set; }
        public int count { get; set; }
        public bool feasible { get; set; }
        public Dictionary<string, RouteResult> route { get; set; }
    }
  public class RouteResult
    {
        public string index { get; set; }
        public string name { get; set; }
        public int arrival { get; set; }
        public double distance { get; set; }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多