Hi ! I’m trying to do those things :
1- read a json
2- select some data inside the json
3- generate a new json
I’m stuck at 3) I try to generate a json from objects created by a for loop. Also if you have any documentation about simplejson it would be appreciated because i’m a bit lost.
public class CollectCards : MonoBehaviour
{
public string set;
public string Rid;
public string Rname;
public string Rset;
// Use this for initialization
void Start ()
{
string str = Read ();
JSONNode cardData = JSON.Parse (str);
string[] setlist = new string[] {
"Basic",
"Advanced",
"Expert"
};
for (int j=0; j<setlist.Length; j++) {
set = setlist [j];
string verif = "green";
for (int i =0; i<cardData[set].Count; i++) {
if (cardData [set] *[verif] != null) {*
_ Rname = cardData [set] [“name”].Value;_
* }*
* } else*
Rname = “none”;
Rid = cardData [set] [“id”].Value;
Rset = setlist [j];
Card carte = new Card (Rid, Rname,Rset);
// I’M STUCK HERE, The idea is to have “Add carte to Json File”//
}
}
}
string Read()
{
StreamReader sr = new StreamReader (Application.dataPath + “/Resources/Cards.json”);
string content = sr.ReadToEnd ();
sr.Close();
return content;
}
}
public class Card {
public string id;
public string name;
public string cardset;
public Card(string id, string name, string cardset)
{
this.id = id;
this.name = name;
this.cardset=cardset;
}
}
Thank you for your help !