newtonsoft로 json 배열을 어떻게 역 직렬화 할 수 있습니까?
여기 내 json 파일 :
{
"one": [
{
"one":"1",
"two":"2",
"three":"3"
},
{
"one":"1",
"two":"2",
"three":"3"
}
],
"two": [
{
"one":"1",
"two":"2",
"three":"3"
}
]
}
내 코드는 다음과 같습니다.
myList= JsonConvert.DeserializeObject <List<MyClass>>(jsonFile);
public class MyClass
{
public string one{ get; set; }
public string two { get; set; }
public string three { get; set; }
}
내 json 파일을 변경해야 할 수도 있습니다.
클래스는 JSON 구조와 일치해야합니다. 다음과 같이 표시되어야합니다.
public class Foo
{
[JsonProperty("one")]
public string One { get; set; }
[JsonProperty("two")]
public string Two { get; set; }
[JsonProperty("three")]
public string Three { get; set; }
}
public class RootObject
{
[JsonProperty("one")]
public List<Foo> One { get; set; }
[JsonProperty("two")]
public List<Foo> Two { get; set; }
}
이제 제대로 직렬화 해제됩니다.
Console.WriteLine(JsonConvert.DeserializeObject<RootObject>(json));
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다