- Home /
New constructor help needed for JSON keyvalue pair
In order to instantiate my prefab(consisting of 2 strings) I have a constructor that used to work, now after converting to JSON(BoomLagoon lib) from SQLite, I have an error saying it can't convert a list to a keyvalue pair.
for(int i = 0; i< NameList.Count; i++)
{
GameObject bnObj = Instantiate(NamePrefab);
MyName tmpName = NameList[i];
bnObj.GetComponent<NameScript>().DisplayName(tmpName.TheName, tmpName.TheImage);
bnObj.transform.SetParent(Displayparent);
}
Then there are 2 constructors:
public class NameScript : MonoBehaviour
{
public GameObject Name;
public GameObject Image;
public void DisplayName(string Name, string Image )
{
this.Name.GetComponent<Text>().text=Name;
this.Image.GetComponent<Text>().text=Image;
}
}
and
public class MyName
{
public string TheName{get; set;}
public string TheImage{get; set;}
public MyName( string Name, string Image)
{
this.TheName=Name;
this.TheImage=Image;
}
}
Seems like I need to change the constructor so it will work with the Key Value Pair, but I'm not quite sure how to do that. Any help would be appreciated. Thanks!
What is "NameList" and what does the error say exactly. You usually get a file reference, a line number and usually some sort of error number.
Also how does your JSON look like and how do you read it / initialize your structures.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Converting WWW to list for instatiation 0 Answers
A node in a childnode? 1 Answer
Instantiate a prefab from jsonarray? 1 Answer