XML反序列化

public class L4 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        string path = Application.persistentDataPath + "/Test.xml";
        //判断文件是否存在
        if (File.Exists(path))
        {
            //反序列化 XmlSerializer中的Deserialize
            //读取文件
            using(StreamReader readr = new StreamReader(path))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Test));
                Test t = serializer.Deserialize(readr) as Test;
            }
        }
    }
        //List对象如果有默认值的话,反序列化的时候会多出来数据,所以最好不要在申明的时候就初始化
}
posted @ 2025-03-24 17:53  cannedmint  阅读(11)  评论(0)    收藏  举报