Json Array returns null value

This is my w.text which is the json array

{
“soldier”: [{
“id”: “1057”,
“user_id”: “133”,
“soldier_level”: “1”
}, {
“id”: “1058”,
“user_id”: “133”,
“soldier_level”: “1”
}, {
“id”: “1059”,
“user_id”: “133”,
“soldier_level”: “1”
}, {
“id”: “1060”,
“user_id”: “133”,
“soldier_level”: “1”
}, {
“id”: “1061”,
“user_id”: “133”,
“soldier_level”: “1”
}]
}

Then I have these classes

[System.Serializable]
    public class SoldierData{
        public int id;
        public int user_id;
        public int soldier_level;
    }

[System.Serializable]
    public class SoldierDataList{
        public SoldierData[] soldierData;
    }

Then to I use this to decode the json array

IEnumerator getData(WWW w){
        yield return w;
        soldier = JsonHelper.FromJson <SoldierDataList> (w.text);
        print(soldier);
}

and it returns Null.
I have also almost the same code that works but just for a non-array json. Thanks! :slight_smile:

Your json text needs to contain a ‘soldierData’ rather than a ‘soldier’ (so it matches up with the array names). If you change the ‘solider’ at the top it seems to work ok for me.

1 Like

It still returns null, but I re-read other threads and got it already! Thanks to your help that the ‘soldier’ variable needs to be match on the json array text. :slight_smile:

This was the link that i re-read