[英]When I try to read the Json file I get the error "JSON parse error Invalid value"
[英]Json reader exception when I try to read a file
在我的應用程序中,我可以插入注釋,並使用以下方法創建它:
public class Note
{
public string FraseGiorno { get; set; }
public string Nota { get; set; }
public string Data { get; set; }
}
string NotesFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Note.json");
ObservableCollection<Note> listNote = new ObservableCollection<Note>();
private async void Save_Clicked(object sender, EventArgs e)
{
await CreateNote.TranslateTo(0, 600, 500, Easing.SinIn);
Note NoteNew = new Note();
if (CheckBox.IsChecked = true)
{
NoteNew = new Note
{
FraseGiorno = obj1.FraseGiornaliera,
Nota = TestoNota.Text,
Data = DateTime.Today.ToString().Remove(10, 9),
};
}
else
{
NoteNew = new Note
{
Nota = TestoNota.Text,
Data = DateTime.Today.ToString().Remove(10, 9),
};
}
using (StreamWriter file = File.CreateText(NotesFile))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, NoteNew);
}
listNote.Add(NoteNew);
}
當用戶移動到另一個頁面時,他可以閱讀他的筆記:
if (File.Exists(NotesFile))
{
var Note = JsonConvert.DeserializeObject<Note>(File.ReadAllText(NotesFile));
}
這里拋出一個異常,但我不明白為什么
Newtonsoft.Json.JsonReaderException: '完成讀取 JSON 內容后遇到的附加文本:{. 路徑'',第 1 行,position 34。 塊引用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.