我在json.net序列化程序中遇到了一个奇怪的问题。这是序列化器的代码。我认为这没有错:
var info = new Info("Peter", 25);
var filePath = Path.Combine(Application.dataPath, "test.xml");
FileStream stream = new FileStream(Path.Combine(Application.dataPath, "test.xml"), FileMode.Open);
var writer = new BsonWriter(stream);
var serializer = new JsonSerializer();
serializer.Serialize(writer, info);
stream.Close();
和Info类:
public class Info
{
public string name;
public int age;
public Info(string name, int age)
{
this.name = name;
this.age = age;
}
}
当此序列化时,会出现一些奇怪的字符,而不是json有效括号。对于许多数据来说,这有点难以理解:
而且年龄似乎也没有序列化。使用的字符集有问题吗?对我来说,如果我可以检查一下,它非常方便,通过查看文件,所有序列都可以正确序列化。同样,为序列化程序设置缩进设置也没有什么不同。我怎样才能解决这个问题?
呼唤远方
相关分类