Exemple #1
0
 public static void JsonToCSV(string path)
 {
     try
     {
         using (StreamReader sr = new StreamReader(path))
         {
             List <string> contents = ParseJsonToCSV.ConvertJsonToCSV(sr);
             if (contents != null && contents.Count > 0)
             {
                 StreamWriter sw = File.CreateText(path.Replace("bytes", "csv"));
                 foreach (string item in contents)
                 {
                     sw.WriteLine(GB2312UnicodeConverter.ToGB2312(item));
                 }
                 sw.Close();
             }
             else
             {
                 UnityEngine.Debug.LogError("JsonToCSV null");
             }
         }
     }
     catch (Exception e)
     {
         UnityEngine.Debug.Log("The process failed: " + e.ToString());
     }
 }
Exemple #2
0
        public static void ParseCSVFormat2JOSN(string path)
        {
            try {
                using (StreamReader sr = new StreamReader(path)) {
                    string source = sr.ReadLine().ToString();

                    List <string> myKeywords = ParseCSV.splitBaseDouHao(source);

                    StreamWriter sw = File.CreateText(path.Replace("csv", "bytes"));

                    string        temp = string.Empty;
                    List <string> contents;
                    while (sr.Peek() >= 0)
                    {
                        temp     = sr.ReadLine().ToString();
                        contents = ParseCSV.splitBaseDouHao(temp);
                        while (contents.Count < myKeywords.Count)
                        {
                            temp += "\\n" + sr.ReadLine().ToString();

                            contents = ParseCSV.splitBaseDouHao(temp);
                        }
                        if (myKeywords != null)
                        {
                            string willWrite = "{";
                            for (int i = 0; i < myKeywords.Count; i++)
                            {
                                int   num  = 0;
                                float fnum = 0f;

                                if (!string.IsNullOrEmpty(contents[i]))
                                {
                                    willWrite += Replace(myKeywords[i], contents[i]);
                                }
                                if (i < myKeywords.Count - 1)
                                {
                                    if (willWrite.Equals(string.Empty))
                                    {
                                    }
                                    else
                                    {
                                        willWrite += ",";
                                    }
                                }
                            }
                            willWrite += "}";
                            sw.WriteLine(GB2312UnicodeConverter.ToGB2312(willWrite));
                        }
                    }
                    sw.Close();
                }
            } catch (Exception e) {
                UnityEngine.Debug.Log("The process failed: " + e.ToString());
            }
        }