JsonHelper.cs 557 B

1234567891011121314151617181920212223
  1. using System;
  2. using UnityEngine;
  3. namespace Plugins.CxShine.net
  4. {
  5. // 出处 :https://forum.unity3d.com/threads/how-to-load-an-array-with-jsonutility.375735/#post-2585129
  6. public class JsonHelper
  7. {
  8. public static T[] getJsonArray<T>(string json)
  9. {
  10. var newJson = "{ \"array\": " + json + "}";
  11. var wrapper = JsonUtility.FromJson<Wrapper<T>>(newJson);
  12. return wrapper.array;
  13. }
  14. [Serializable]
  15. private class Wrapper<T>
  16. {
  17. public T[] array;
  18. }
  19. }
  20. }