![](/img/trans.png)
[英]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.