JSON을 C#에서 deserialize하려고하는데 NullReferenceException이 발생하고 이유를 모르겠습니다. 여기 JSON을 C#에서 Deserialzing
는 JSON 내가 구문 분석을 시도하고있다 :{"Entries": {"Entry": {"day": "28","month": "10","year": "1955","type": "birthday","title": "Bill Gates was born!","picture": "","video": ""}}}
을하고이 코드
public class Entry
{
public string day { get; set; }
public string month { get; set; }
public string year { get; set; }
public string type { get; set; }
public string title { get; set; }
public string picture { get; set; }
public string video { get; set; }
}
public class Entries
{
public List<Entry> entry { get; set; }
}
private void buttonSearch_Click(object sender, EventArgs e)
{
string json = new StreamReader("events.json").ReadToEnd();
var entries = JsonConvert.DeserializeObject<Entries>(json);
MessageBox.Show(entries.entry[0].day); // NullReferenceException
}
왜이 오류가 무엇입니까 나는 그것을 어떻게 해결할 수를 사용하고 있습니다?
내가
{"Entries": ["Entry": {"day": "28","month": "10","year": "1955","type": "birthday","title": "Bill Gates was born!","picture": "","video": ""}]}
에 JSON을 변경할 때 얻을 After parsing a value an unexpected character was encountered: :. Path 'Entries[0]', line 1, position 20.
내가 JSON과 하나의 울부 짖는 소리와 함께 연주
편집이 나를 위해 일한 :
[{"day": "28","month": "10","year": "1955","type": "birthday","title": "Bill Gates was born!","picture": "","video": ""}]
디버거를 연결합니다. 실제 비 직렬화 된 데이터를 검사하십시오. 어쨌든 문제는 * JSON에 배열이 없다는 것입니다. – user2246674
디버거는 항목이 null이며 그 이유를 알 수 없다고 말합니다. – armin
".. 문제는 * JSON에 배열이 없습니다"입니다. 디시리얼라이저는'List entry'를 채울 수있는 배열이 필요합니다. 디시리얼라이저 신뢰 - 필드를 올바르게 채우지 않으면 소스 데이터가 정렬되지 않은 것일 수 있습니다. 또한 일부 이름 (예 : 항목 대 항목)이 올바르지 않습니다. –
user2246674