json 응답을 역 직렬화하는 중이며 null 값을 얻습니다.
{
"response": {
"status": {
"version": "4.2",
"code": 0,
"message": "Success"
},
"start": 0,
"total": 12,
"biographies": [{
"text": "\"Radiohead\" are an English alternative rock band from Abingdon, Oxfordshire, formed in 1985. The band consists of Thom Yorke (vocals, guitars, piano), Jonny Greenwood (guitars, keyboards, other instruments), Ed O'Brien (guitars, backing vocals), Colin Greenwood (bass, synthesisers) and Phil Selway (drums, percussion).",
"site": "wikipedia",
"url": "http://en.wikipedia.org/wiki/Radiohead",
"license": {
"type": "cc-by-sa",
"attribution": "n/a",
"url": ""
}
}]
}
}
이것은 위의 json을 직렬화하는 데 사용하는 클래스입니다.
public class Response : IResponse
{
public Status status { get; set; }
public string start { get; set; }
public string total { get; set; }
public List<Biography> biographies { get; set; }
}
응답에는 둘 이상의 전기가 포함됩니다.
public class Biography
{
public string text { get; set; }
public string site { get; set; }
public string url { get; set; }
public LicenseInfo license { get; set; }
}
public class LicenseInfo
{
public string type { get; set; }
public string attribution { get; set; }
public string url { get; set; }
}
Response
클래스에 대해 모든 값이 null을 반환하는 이유는 무엇 입니까?
이 경우 T
입니다 Response
:
return string.IsNullOrEmpty(response) ? default(T) : JsonConvert.DeserializeObject<T>(response);
역 직렬화하려면 response
속성 을 포함하는 클래스를 만들어야 합니다.
public class RootObject
{
public Response response { get; set; }
}
그런 다음 RootObject
클래스를 사용하여 역 직렬화합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다