I have set up some simple form controls like radio buttons, sliders, checkboxes, and other similar things. I want to be able to load data from a JSON file. Here’s some example JSON data:
[
[
{
"type": "text",
"text": "Hello world! This text is on page 1"
}
],
[
{
"type": "text",
"text": "Page 2 has text and a slider"
},
{
"type": "slider",
"minValue": "0.0",
"maxValue": "100.0",
"defaultValue": "50.0",
"minLabel": "Smallest Value",
"midLabel": "Middle Value",
"maxLabel": "Largest Value"
}
]
]
I want my program to be able to read data from this JSON file into an object like an array of arrays of dictionaries so that I can pass the JSON data to the functions that I use to create the objects onscreen, but this has been giving me a lot of trouble. The main issue I ran into is that the Unity JsonUtility doesn’t seem to support dictionaries, according to someone on stackoverflow. I tried a bunch of different things but even when only using arrays of strings, I couldn’t get the JsonUtility to actually save or load anything - if I created an array in C# and tried to save it as a JSON string, I just got “{}”. I tried other libraries like FullSerializer but they were unsuccessful as well. Another issue is that C# doesn’t do anonymous dictionaries, so all of my data has to be stored as a string (as seen above), even floats, integers, and booleans. I’m a JavaScript developer and this seems like it should be a really simple task to me but I cannot seem to make C# do what I want it to do. Is there something I am doing wrong? What is the correct way to store this data in a text file that can be written to by other programs? My end goal is to write a separate application in PHP/JS that generates the files and then the Unity application reads the data via an HTTP GET request and generates the appropriate elements onscreen based off what it receives.
Thanks