我正在尝试做这些事情:
1-读一个json
2-选择json中的一些数据
3-生成一个新的json
我坚持3)我尝试从for循环创建的对象生成json。此外,如果您有关于simplejson的任何文档,我将不胜感激,因为我有点迷失。
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];
for (int i =0; i<cardData[set].Count; i++) {
Rid = cardData [set] [i] ["id"].Value;
Rname = cardData [set] [i] ["name"].Value;
Rset = setlist [j];
Card carte = new Card (Rid, Rname,Rset);
I'M STUCK HERE;
}
}
}
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;
}
}