json을 Array로 얻는 경우 Array로만 deserialize하지 않는 이유는 무엇입니까? 그런 다음 .ToList()
메서드를 사용 하여 배열을 List
.
수업은 다음과 같아야합니다.
public class Message
{
public int id { get; set; }
public int previous { get; set; }
public int last_update { get; set; }
public string html { get; set; }
}
public class RootObject
{
public string robots { get; set; }
public List<Message> messages { get; set; }
public List<int> messageIds { get; set; }
public string onlineUsers { get; set; }
public string reverse { get; set; }
public int lastrefresh { get; set; }
public string motd { get; set; }
public int numInChat { get; set; }
public bool twelveHour { get; set; }
public string _visitor_conversationsUnread { get; set; }
public string _visitor_alertsUnread { get; set; }
}
그리고 전체 jSon을 RootObject
클래스로 직접 역 직렬화 할 수 있어야합니다 . deserialize하려면 Newtonsoft.Json dll (Nuget에서 사용 가능)을 제안합니다.
RootObject rootObject = JsonConvert.DeserializeObject<RootObject>(jsonString);
그러면 요청한대로 속성에 액세스 할 수 있습니다.
http://json2csharp.com/의 도움을 받아 jSon에서 클래스를 생성했습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다