public static void toJson() { var select = Selection.activeObject; var path = AssetDatabase.GetAssetPath(select); Dictionary <string, string[]> dic = ExcelTool.ToArrayListFromExcel(path, 1); string newPath = path.Replace(path.Substring(path.LastIndexOf(".")), ".json"); if (System.IO.File.Exists(newPath)) { System.IO.File.Delete(newPath); } using (System.IO.FileStream fs = System.IO.File.Create(newPath))// file = new System.IO.File()) { System.IO.StreamWriter sw = new System.IO.StreamWriter(fs); sw.Write(ExcelTool.ToJsonFromDic(dic)); sw.Close(); } }
public static void LoadJsonFromExcel_pushStr() { string epath = Application.streamingAssetsPath + "/pushStrConfig.xlsx"; string jpath = Application.dataPath + "/Resources/pushStr.json"; PushStr ps = null; Dictionary <string, string[]> strs = ExcelTool.ToArrayListFromExcel(epath); if (strs != null) { ps = new PushStr(); foreach (var tem in strs) { Debug.Log(tem.Value.Length + " str = " + tem.Value[0] + " key = " + tem.Key); ps.Add(tem.Key); } } if (ps != null) { try { string str = JsonMapper.ToJson(ps); Debug.Log("json str = " + str); if (System.IO.File.Exists(jpath)) { System.IO.File.Delete(jpath); } System.IO.FileStream fs = new System.IO.FileStream(jpath, System.IO.FileMode.CreateNew); System.IO.StreamWriter sw = new System.IO.StreamWriter(fs); sw.WriteLine(str); sw.Close(); fs.Close(); } catch (System.Exception ex) { Debug.LogError("ex = " + ex.ToString()); } } }