2

C# アプリケーションで HttpClient を使用して Web API にアクセスしています。この種の Web API は初めてです (通常は WCF サービスを行っています)。

応答の 1 つが次のようになります。

{
    "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
    }
}

私のモデルクラスはどのようになりますか? ネスティングをどのように説明しますか?

4

1 に答える 1