Unity

[Unity]JSON 파싱하기

Guk-blog 2019. 3. 26. 09:54
728x90
반응형

using System;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class JSONSerializeFormat : MonoBehaviour

{

    public static T[] FromJson<T>(string json)

    {

        Serialize<T> serialize = JsonUtility.FromJson<Serialize<T>>(json);

        return serialize.items;

    }


    public static string ToJson<T>(T[] array)

    {

        Serialize<T> serialize = new Serialize<T>();

        serialize.items = array;

        return JsonUtility.ToJson(serialize);

    }


    [Serializable]

    private class Serialize<T>

    {

        public T[] items;

    }

}

728x90
반응형