hello, i’m using a c# script to read a jsonfile i created, having a public class ,constructor.
btw using LitJson for json compatibility…
I wanted to read the file, and debug.log it.
here is my script
using LitJson;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class Base_campos : MonoBehaviour
{
private List<Campos> database = new List<Campos>();
private JsonData CamposData;
void Start()
{
// Campos campos = new Campos(0, "tste", "");//cria instancia/copia
//database.Add(campos);
//Debug.Log(database[0].Texto);
CamposData = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/StreamingAssets/campos.json.json"));
ConstructCamposDatabase();
Debug.Log(database[0].Texto);
}
void ConstructCamposDatabase()
{
for (int i = 0; i < CamposData.Count; i++)
{
database.Add(new Campos((int)CamposData<em>["id"], CamposData_["texto"].ToString(), CamposData*["link"].ToString()));*_</em>
}
}
}
public class Campos
{
public int ID { get; set; }
public string Texto { get; set; }
public string Link { get; set; }
public Campos(int id, string texto, string link)
{
this.ID = id;
this.Texto = texto;
this.Link = link;
}
}
i’m getting the error:
KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[System.Int32,System.Int32[]].get_Item (Int32 key) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
LitJson.JsonReader.Read ()
Rethrow as JsonException: Invalid token ‘123’ in input string
LitJson.JsonReader.Read ()
LitJson.JsonMapper.ReadValue (LitJson.WrapperFactory factory, LitJson.JsonReader reader)
LitJson.JsonMapper.ReadValue (LitJson.WrapperFactory factory, LitJson.JsonReader reader)
LitJson.JsonMapper.ToWrapper (LitJson.WrapperFactory factory, System.String json)
LitJson.JsonMapper.ToObject (System.String json)
Base_campos.Start () (at Assets/scripts/Base_campos.cs:16)
Any idea on how to solve it?