0
對不起,我的英語,好吧,我試圖反序列化在UNITY和C#上的json文件, 當我得到一個對象列表(int,string,浮動,布爾內部)上沒有problema, JSON BASIC STRUCTURE反序列化團結和c#,列表到另一個列表
但是,當我的元素內部有另一個列表中談到的問題的列表,我的意思是裏面的另一個列表 json second structure
我的C#代碼列表中,我加載JSON文件,(我得到這個配置,因爲它適用於Android和Unity編輯器)
public void loadjsonfile(string jsonfilename)
\t {
\t \t TextAsset file = Resources.Load(jsonfilename) as TextAsset;
\t \t jsonData = file.ToString();
\t }
\t public List<club> findClubsIn(string jsonFilename, string leagueName)
\t {
\t \t List<club> clubFound = new List<club>();
\t \t if(jsonFilename.Equals("european_club"))
\t \t {
\t \t \t loadjsonfile (jsonFilename);
\t \t \t europeanClub uefaclubs = JsonUtility.FromJson<europeanClub> (jsonData);
\t \t \t List<club> clubList = uefaclubs.europeanClubs;
\t \t \t foreach (club cl in clubList)
\t \t \t {
\t \t \t \t if (cl.league.Equals (leagueName))
\t \t \t \t {
\t \t \t \t \t //Debug.Log (cl.name);
\t \t \t \t \t clubFound.Add (cl);
\t \t \t \t }
\t \t \t }
\t \t \t return clubFound;
\t \t }
\t \t clubFound.Clear();
\t \t return clubFound;
\t }
現在,在同一個班,我得到這個
[System.Serializable]
public class cab
{
\t public float domestic_league;
\t public float domestic_cup;
\t public float domestic_s_cup;
\t public float euro_champ_cup;
\t public float euro_league;
\t public float euro_s_cup;
\t public float inter_club_champ;
}
[System.Serializable]
public class kits
{
\t public string h_m_color;
\t public string h_s_color;
\t public string a_m_color;
\t public string a_s_color;
\t public string kit_sponsor;
\t public string kit_supplier;
\t public string sp_contract;
\t public string supp_contract;
}
[System.Serializable]
public class transf
{
\t public float transfer_budget;
\t public float wage_budget;
\t public float foreign_p_bias;
\t public float transfer_activity;
\t public bool only_national;
}
[System.Serializable]
public class fac
{
\t public string stadium;
\t public float stadium_cap;
\t public string training_facilities;
}
[System.Serializable]
public class club
{
\t public int club_id;
\t public string sprite_id;
\t public string name;
\t public string confederation;
\t public string nation;
\t public string league;
\t public float overall;
\t public float international_rep;
\t public float domestic_rep;
\t public string financial_state;
\t public float youth_policy;
\t public string second_team;
\t public float market_value;
\t public string manager;
\t public float squad_size;
\t public string continental_comp;
\t public string continental_s_cup;
\t public List<fac> facilities;
\t public List<transf> transfers;
\t public List<kits> kit;
\t public List<cab> cabinet;
}
[System.Serializable]
public class europeanClub
{
\t public List<club> europeanClubs;
}
但是,當我嘗試這樣做的問題來了,我真的不知道是什麼我做得不好,希望你能幫忙,提前致謝。
JsonDataHandler data = new JsonDataHandler();
\t \t \t List<club> clubsFound = data.findClubsIn ("european_club","Premier League");
\t \t \t List<fac> fac = new List<fac>();
\t \t \t foreach(club cl in clubsFound)
\t \t \t {
\t \t \t \t fac.Add (cl.facilities);
\t \t \t }
\t \t \t foreach(fac fs in fac)
\t \t \t {
\t \t \t \t Debug.Log (fs.stadium);
\t \t \t }
錯誤
資產/腳本/ scrollClub.cs(42,9):錯誤CS1502:用於`System.Collections.Generic.List.Add最好重載的方法匹配(FAC )'有一些無效參數