2013-07-18 12 views
2

C# 응용 프로그램에서 HttpClient를 사용하여 웹 API에 액세스하고 있습니다. 나는 이런 종류의 웹 API에 익숙하지 않다 (나는 보통 WCF 서비스를한다).중첩 된 JSON 응답에 내 모델 클래스를 설정하려면 어떻게해야합니까?

{ 
    "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를 얻을 수 그 값이 채워진 물체. Magic.

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

어떤 것처럼 내 모델 클래스의 모양을

는 API의 다음 비트는이 같은 응답을 반환? 중첩을 어떻게 설명합니까?

http://json2csharp.com

당신은 단순히 JSON URL 또는 심지어 JSON을 붙여 넣습니다

나는이 위대한 발견 : 당신이 지금이 문제를 해결하지 않은 경우

답변

1

이 내가 찾은 것입니다 그것을 중첩 시키면 모델 클래스가 반환됩니다. 또는 Visual Studio에서 JSOn 및 편집> 선택하여 붙여 넣기>를 복사하여 모델 클래스를 반환 할 수도 있습니다.

관련 문제