无法从具有嵌套属性的其他API服务访问响应。
例如,这里是原始REST响应:
"count": 5,
"results": [
{
"suggestion": "1 Wonston Road, Southampton, SO16 ...",
"matched": [[ 29, 37 ]],
{
"suggestion": "3 Wonston Road, Southampton, SO16 ...",
"matched": [[ 29, 37 ]],
Suggestion and Match是结果中的嵌套属性。
在我的代码中获得响应的函数是
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
?目前,嵌套属性存储在结果中。
答案 0 :(得分: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; } }