FileTool.cs 840 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using LitJson;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using UnityEngine;
  7. public class FileTool
  8. {
  9. public static JsonData ReadJson(string path)
  10. {
  11. try
  12. {
  13. if (File.Exists(path))
  14. {
  15. FileStream fs = new FileStream(path, FileMode.Open);
  16. StreamReader sr = new StreamReader(fs);
  17. JsonData values = JsonMapper.ToObject(sr.ReadToEnd());
  18. if (fs != null)
  19. {
  20. fs.Close();
  21. }
  22. if (sr != null)
  23. {
  24. sr.Close();
  25. }
  26. return values;
  27. }
  28. }
  29. catch (Exception e)
  30. {
  31. Debug.LogException(e);
  32. }
  33. return null;
  34. }
  35. }