2017-08-18 67 views
1

我嘗試與RouteXL建立連接,但在api響應中,我得到一個json,可能無效。奇怪的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}}} 
+1

[LINQ與Json.net JSON(https://www.newtonsoft.com/json/help/html/LINQtoJSON.htm)? – crashmstr

+0

這是一個有效的json – Hackerman

+2

嘗試將'route'部分反序列化爲'Dictionary '或者'Dictionary '。我確定這是一個重複的地方... –

回答

0

感謝@JonSkeet它就像一個魅力。

這對谷歌來說很難。但是,如果有誰有sameproblem這裏是我的新類架構

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; } 
    }