XML JSON Dynamic Reading

Looking to see if there is an easy way to integrate dynamic data sets in to unity similar to this in construct2 Game Making Software - Construct 3

Basically we would have a standard set of data in an xml or json format as the default data set for a game. However a user has the option to put a different data set on one of our servers that is then accessible to be loaded into the game by that user or other is the data set is public. Think of it as a set of questions to be answered by the user but the questions and answers can be changes.

I found on thread that mention some potential issues with android. Are there any best practice example of this for Unity.

Thanks in advance for your thoughts.

Not meaning to shamelessly plug my asset, but it looks like a good fit for the JSON portion of your question. JSON is more forgiving than XML and most times provides a smaller payload. JSON .NET has an object called JObject that turns your JSON into a key/value pair (or deeper for complex objects), so you can access the data dynamically. As an example, take the following json:

{
   "Key1" : "Foo",
   "Key2" : "Bar",
   "SomeNumberKey" : 5,
   "SomeObject" : {  "Name" : "Dustin" }
}

Now you could process it as follows:

var data = JObject.Parse(jsonString);

var key1 = data.Value<string>("Key1");
var key2 = data.Value<string>("Key2");

var numberKey = data.Value<int>("SomeNumberKey");

var name = data["SomeObject"].Value<string>("Name");

There are other ways to get the values, process the data, etc. It supports collections and such as well. Additionally, it gives flexibility. The above shows the option of using JObject, but if the user doesn’t actually need their end to be dynamic, then they could create a class up front:

//SomeObject object
public class Person
{
   public string Name {get; set;}
}

//Outer class
public class SomeData
{
    public string Key1 {get; set;}
    public string Key2 {get; set;}
    public int SomeNumberKey {get; set;}

    public Person SomeObject {get; set;}
}

Now they could just do:

var data = JsonConvert.DeserializeObject<SomeData>(jsonString);

So it does provide a lot of options for working with the data.

There’s SimpleJSON script freely available from here:
http://wiki.unity3d.com/index.php/SimpleJSON

For simple configs it will work fine, although I wouldn’t recommend exporting hundreds of megabytes of json data (I did that, it isn’t exactly fast). It can handle nested data too.

For loading user-created json files, just put them into Resources folder, then you can load them using Resources.Load() function, as text assets.

Thanks for the insights. Much appreciated.