예제 #1
0
    /// <summary>
    /// Adds the specified object to a prexisting JSON file and creates a JSON file if the file does not exist
    /// </summary>
    public static void AddToJSONFile <T>(T inObjectToSave, string inFileName)
    {
        if (GetJSONText(inFileName) == null)
        {
            CreateJSONFile(inObjectToSave, inFileName);

            string initialJSONText = JSONUtils.ToJSON(inObjectToSave);
            WriteTextToFile(initialJSONText, inFileName);

            return;
        }

        List <T> jsonObjects = GetObjectsFromJSON <T>(inFileName).OfType <T>().ToList();

        jsonObjects.Add(inObjectToSave);

        string newJSONText = JSONUtils.ToJSON(jsonObjects.ToArray());

        WriteTextToFile(newJSONText, inFileName);
    }
예제 #2
0
    /// <summary>
    /// Creates a JSON file from the specified object and overrides any JSON file with the same name
    /// </summary>
    public static void CreateJSONFile <T>(T inObjectToSave, string inFileName)
    {
        string jsonText = JSONUtils.ToJSON(inObjectToSave, true);

        WriteTextToFile(jsonText, inFileName);
    }