역 직렬화하려는 JSON 파일이 있습니다.
[
{
"colorData": [
255,
255,
255
],
"Neighbours": [
{
"Item1": 0,
"Item2": [
{
"colorData": [
255,
255,
255
],
"numberOfExamples": 188
},
{
"colorData": [
255,
24,
0
],
"numberOfExamples": 15
}
]
},
{
"Item1": 1,
"Item2": [
{
"colorData": [
255,
255,
255
],
"numberOfExamples": 188
},
{
"colorData": [
255,
24,
0
],
"numberOfExamples": 15
}
]
},
{
"Item1": 2,
"Item2": [
{
"colorData": [
255,
255,
255
],
"numberOfExamples": 188
},
{
"colorData": [
255,
24,
0
],
"numberOfExamples": 15
}
]
},
{
"Item1": 3,
"Item2": [
{
"colorData": [
255,
255,
255
],
"numberOfExamples": 188
},
{
"colorData": [
255,
24,
0
],
"numberOfExamples": 15
}
]
}
]
}
]
이것은 내가 그것을 deserialize하려는 객체입니다.
public partial class ImageBrainData_Reader
{
public int[] colorData { get; set; }
public List<Neighbour_Reader> neighbours { get; set; }
}
public partial class Neighbour_Reader
{
public int direction { get; set; }
public List<NeighbourData_Reader> neighbourData_Reader { get; set; }
}
public partial class NeighbourData_Reader
{
public int[] colorData { get; set; }
public int numberOfExamples { get; set; }
}
그리고 이것은 파일에서로드하기 위해 내가하는 일입니다.
List<ImageBrainData_Reader> dataRead = JsonConvert.DeserializeObject<List<ImageBrainData_Reader>>(File.ReadAllText(fileName + ".json"));
첫 번째 부분 ( colorData
)이 가져 와서 정확한 양의 nested Neighbours
를 가져 오지만, 그들 ( Item1
및 Item2
) 의 데이터 는 읽히지 않습니다. 데이터를 가져 오는 대신 기본값 (각각 0 및 null)을 기본값으로 사용합니다.
Json.Net은 알 수있는 방법이 없습니다 Item1
에 대한지도 direction
및 Item2
에지도를 neighbourData_Reader
당신이 그것을 말할하지 않는합니다. [JsonProperty]
아래와 같이 일부 속성 을 추가하거나 속성 이름을 JSON과 일치 시켜야합니다 .
public partial class Neighbour_Reader
{
[JsonProperty("Item1")]
public int direction { get; set; }
[JsonProperty("Item2")]
public List<NeighbourData_Reader> neighbourData_Reader { get; set; }
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다