HTTP 응답으로 JSON 문자열을받습니다. 내가 Newtonsoft.Json 라이브러리가JSON 문자열 직렬화 (Newtonsoft.JSON)
response: {
count: 524,
items: [{
id: 318936948,
owner_id: 34,
artist: 'The Smiths',
title: 'How Soon Is Now',
duration: 233,
url: 'link',
genre_id: 9
}, {
id: 312975563,
owner_id: 34,
artist: 'Thom Yorke',
title: 'Guess Again!',
duration: 263,
url: 'link',
genre_id: 22
}]
}
, 및 클래스 응답 및 항목 :처럼이 문자열은 보이는
[JsonObject(MemberSerialization.OptIn)]
class Response
{
[JsonProperty("count")]
public int count { get; set; }
[JsonProperty("items")]
public List<Item> items { get; set; }
}
[JsonObject(MemberSerialization.OptOut)]
class Item
{
public string aid { get; set; }
public string owner_id { get; set; }
public string artist { get; set; }
public string title { get; set; }
public string duration { get; set; }
public string url { get; set; }
public int lyrics_id { get; set; }
public int album_id { get; set; }
public int genre_id { get; set; }
}
와 나는 그런 식으로 직렬화 :
Response r = JsonConvert.DeserializeObject<Response>(line);
그것은하지 않습니다 "r"은 null로 유지됩니다. 내가 왜 틀렸어? 왜? 컴파일 중이지만 예외는 없습니다.
Json을 http://jsonformatter.curiousconcept.com/에 붙여 넣을 때 "문자열을 큰 따옴표로 묶어야합니다. [코드 17, 구조 2]"와 같은 오류가 발생합니다. – dbc
Json이 잘못한 것 같습니다. check here http://json2csharp.com/ – loop
또한'response'는 일부 구조체의 필드/속성이지만 보이지 않습니다. – dbc