Loading Json File with Arrays from Server

So i got an Json File like:

{
    "name": "Project 1",
    "views": [
        { "href": "YourURL" }
    ]
}

My own classes looks like this

[System.Serializable]
public class JsonClass  {
    public string name;
    public views[] views;
    public JsonClass(string jsonString) {
        name = jsonString;
    }
    public JsonClass() { }
}
[System.Serializable]
public class views
{
    public string href;
}

I load the json file with following which i found in the forum aswell:

public class JsonHandler : MonoBehaviour {

    [RuntimeInitializeOnLoadMethod]
    IEnumerator Start()
    {
        string url = "anotherURL";
        WWW www = new WWW(url);
        yield return www;
        if (www.error != null)
        {
            Debug.Log("ERROR: " + www.error);
        }
        else
        {
            Debug.Log("No Error");
            Debug.Log(www.text);
            Debug.Log(ProcessJson(www.text));
                   }

    }

    private string ProcessJson(string jsonString) {
        JsonClass parsejson = new JsonClass();
        parsejson = JsonUtility.FromJson<JsonClass>(jsonString);
        return parsejson.name;
    }

The name is overwritten right but the views are empty. How can i handle this? I already searched in the Forum but didn´t found a working solution.

Okay, your code looks okay, though I have a few questions:

  1. In ProcessJson(string jsonString) it’s specifically only returning the name, and I don’t see parseJson variable being saved anywhere. So how are you checking the views don’t exist. Is it definitely being saved?

  2. What is the output of “www.text”. Does it contain correctly formatted views as a json string?

Try making the ‘views’ class into a struct or using List instead of views[ ]

I don’t think the Unity Json parser is that robust compared to others, I usually use other 3rd party solutions.

Are you doing this at runtime or in the editor?