Question by
OtherWiseDesign · Sep 03, 2017 at 04:48 PM ·
arrayjsonreading data
Reading an array from a JSON Error
So i'm trying to read an array out of a JSON file but the Error:
ArgumentException: JSON parse error: Missing a colon after a name of object member.
UnityEngine.JsonUtility.FromJson[Item] (System.String json) (at C:/buildslave/unity/build/artifacts/generated/common/modules/JSONSerialize/JsonUtilityBindings.gen.cs:25) itemgrabber.Start () (at Assets/Scripts/System/itemgrabber.cs:27)
keeps coming up. I feal like i'm missing something even though there are no compiler errors. I look up bunch of examples about reading arrays in JSON but I can't figure out what i'm doing wrong.
[Header("ID for ID-Change")]
public int ChangeID = 0;
[Header("Objects to ID-Change")]
public Image changeImage;
public Text changeTextName;
public Text changeTextDiscription;
string ItemsPath;
string Itemdata;
string ItemInfoData;
void Start()
{
ItemsPath = Application.dataPath + "/Items/Items.json";
ItemInfoData = File.ReadAllText(ItemsPath);
Item Temp = JsonUtility.FromJson<Item>(ItemInfoData);
Debug.Log(Temp[1].readID);
}
}
[System.Serializable]
public class Item
{
public int[] readID;
public string[] Name;
public string[] Description;
}
Comment
Answer by OtherWiseDesign · Sep 03, 2017 at 04:59 PM
That's my JSON:
{
"Items":[
{
"id": 0,
"name":"empty",
"description":"Empty!"
},
{
"id": 1,
"name":"Stein",
"description":"Dies ist ein Test-Item das zur Darstellung im Inventar dient!"
},
{
"id": 2,
"name":"Holz",
"description":"Dies ist ein weiteres Test-Item das zur Darstellung im Inventar dient!"
}
]
}