2016-05-13 134 views
0

無法從具有嵌套屬性的其餘API服務訪問迴應。GetSet嵌套屬性

例如這裏的原始REST迴應:

"count": 5, 
"results": [ 
    { 
     "suggestion": "1 Wonston Road, Southampton, SO16 ...", 
     "matched": [[ 29, 37 ]], 
    { 
     "suggestion": "3 Wonston Road, Southampton, SO16 ...", 
     "matched": [[ 29, 37 ]], 

建議和比賽的結果中嵌套屬性。 在我的代碼中得到響應的函數是
IRestResponse<SearchResponse> response = client.Execute<SearchResponse>(request);我已經在這裏使用了休息,並且調用實際上是準確的,因爲我將所有數據恢復爲原始響應的形式。

我已經定義了SearchResponse類作爲

//same for result, match, suggestion. 
private string _count; 
public string Count 
{ 
    get 
    { 
     return _count; 
    } 

    set 
    { 
     _count = value; 
    } 
} 

我如何定義嵌套變量將它們傳遞到SearchResponse.suggestion?目前嵌套的屬性存儲在結果中。

+2

這真的不清楚你問什麼,而只是產生表示JSON結構的適當類。你可以在http://json2csharp.com上這樣做。 – CodeCaster

回答

0
public class Result { 
    public string suggestion { get; set; } 
    public List<List<int>> matched { get; set; } 
    public string format { get; set; } } 

public class RootObject { 
    public int count { get; set; } 
    public List<Result> results { get; set; } } 

http://json2csharp.com的伎倆,謝謝