我在 C# 应用程序中使用 HttpClient 来访问 Web API。我是这种 Web API 的新手(我通常做 WCF 服务)。
其中一个响应如下所示:
{
"access_token": the access token,
"scope": "read",
"expires_in": seconds to expiry,
"refresh_token": a refresh token
}
模型类如下所示:
class AuthResponse
{
public string access_token { get; set; }
public string scope { get; set; }
public int expires_in { get; set; }
public string refresh_token { get; set; }
}
所以当我这样做时:
var result = resposne.Content.ReadAsAsync<AuthResponse>().Result;
我得到了一个 AuthResponse 对象,其中填充了它的值。魔术。
下一位 API 返回如下响应:
{
"data": {
"visible": boolean,
"email": valid e-mail string or null,
"location_string": human-readable location identifier string,
"ad_id": primary key of the ad
},
"actions": {
"change_form": URL to change this ad
"public_view": URL to view this ad's public HTML page
"html_edit": URL to view this ad's HTML edit page
that has more options than the API change_form does
}
}
我的模型课会是什么样子?我如何解释嵌套?