Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LitJson doesnt write empty arrays #98

Closed
chris-rogers-anki opened this issue Nov 12, 2018 · 2 comments
Closed

LitJson doesnt write empty arrays #98

chris-rogers-anki opened this issue Nov 12, 2018 · 2 comments
Labels
Milestone

Comments

@chris-rogers-anki
Copy link

@chris-rogers-anki chris-rogers-anki commented Nov 12, 2018

It seems this has been a problem since 2014.

LitJson does not handle empty lists or arrays as a new JsonData object or as an addition to an existing JsonData object.

These 4 tests in Unity all fail.

using UnityEngine;
using LitJson;
using UnityEditor;
using System.Collections.Generic;
using System.IO;

namespace DefaultNamespace
{
public class TestLitJsonArray : MonoBehaviour
{
[MenuItem("Window/TestLitJsonList")]
static void doTest1()
{
List strings = new List();
JsonData jd = new JsonData();
jd.Add(strings);
File.WriteAllText(Application.streamingAssetsPath+("/arrayTest1.json"),jd.ToJson());
}

    [MenuItem("Window/TestLitJsonList2")]
    static void doTest2()
    {
        List<string> strings = new List<string>();
        JsonData jd = new JsonData(strings);
        File.WriteAllText(Application.streamingAssetsPath+("/arrayTest2.json"),jd.ToJson()); 
    }
    
    [MenuItem("Window/TestLitJsonArray")]
    static void doTest3()
    {
        string[] strings2 = new string[1];  // Im trying to write a 0 length array, it errors if this is 1 or 0
        JsonData jd = new JsonData();
        jd.Add(strings2);
        File.WriteAllText(Application.streamingAssetsPath+("/arrayTest3.json"),jd.ToJson()); 
    }
    
    [MenuItem("Window/TestLitJsonArray2")]
    static void doTest4()
    {
        string[] strings2 = new string[1];
        JsonData jd = new JsonData(strings2);
        File.WriteAllText(Application.streamingAssetsPath+("/arrayTest4.json"), jd.ToJson()); 
    }
}

}

error is
Unable to wrap ... with JsonData

@chris-rogers-anki
Copy link
Author

@chris-rogers-anki chris-rogers-anki commented Nov 13, 2018

here's a real world example of the output:
], "connections": "camerapositionX" : "0", "camerapositionY": "0",

connections should be [] but i'd be ok with null but its blank.

@devlead
Copy link
Member

@devlead devlead commented Feb 14, 2020

Fixed by #115

@devlead devlead closed this as completed Feb 14, 2020
@devlead devlead added the bug label Feb 14, 2020
@devlead devlead added this to the 0.16.0 milestone Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants