Beispiel #1
0
 public static void parse()
 {
     getInfo(() =>
     {
         Debug.Log("开始!!!!");
         ExcleToJson.ToJson(readDir, outDir, files);
         Debug.Log("完成!!!!");
     });
 }
Beispiel #2
0
 public static void ToJson(string r, string o, List <string> fs)
 {
     readDir = r;
     outDir  = o;
     shell.Clear();
     excels.Clear();
     foreach (var v in fs)
     {
         ExcleToJson.ToJson(v);
     }
     foreach (var v in shell)
     {
         if (File.Exists(v))
         {
             File.Delete(v);
         }
     }
 }
Beispiel #3
0
                    private string parseRow(int?r = null)
                    {
                        temp.Length = 0;
                        row         = r == null ? row : r.Value;

                        for (line = 0; line < types.Count; line++)
                        {
                            if (line == 0)
                            {
                                temp.Append("{");
                            }

                            temp.Append(string.Format("\"{0}\":", names[line]));
                            string   s = contents[row][line];
                            Excel    e = null;
                            string[] sp;

                            switch (types[line].ToLower())
                            {
                            case "string":
                                temp.Append(string.Format("\"{0}\"", s));
                                break;

                            case "number":
                                temp.Append(s);
                                break;

                            case "boolean":
                                temp.Append(s.ToLower());
                                break;

                            case "arraystring":
                                sp = s.Split('\\');
                                temp.Append("[");
                                for (int b = 0; b < sp.Length; b++)
                                {
                                    if (b == sp.Length - 1)
                                    {
                                        temp.Append(string.Format("\"{0}\"", sp[b]));
                                    }
                                    else
                                    {
                                        temp.Append(string.Format("\"{0}\",", sp[b]));
                                    }
                                }
                                temp.Append("]");
                                break;

                            case "arraynumber":
                                sp = s.Split('\\');
                                temp.Append("[");
                                for (int b = 0; b < sp.Length; b++)
                                {
                                    if (b == sp.Length - 1)
                                    {
                                        temp.Append(sp[b]);
                                    }
                                    else
                                    {
                                        temp.Append(string.Format("{0},", sp[b]));
                                    }
                                }
                                temp.Append("]");
                                break;

                            case "arrayboolean":
                                sp = s.Split('\\');
                                temp.Append("[");
                                for (int b = 0; b < sp.Length; b++)
                                {
                                    if (b == sp.Length - 1)
                                    {
                                        temp.Append(sp[b]);
                                    }
                                    else
                                    {
                                        temp.Append(string.Format("{0},", sp[b].ToLower()));
                                    }
                                }
                                temp.Append("]");
                                break;

                            case "shell":
                                e = ExcleToJson.ToJson(string.Format("{0}/{1}{2}", filePath.Substring(0, filePath.LastIndexOf('/')), names[line], excelSuffix), true);
                                if (null == e)
                                {
                                    break;
                                }
                                for (int i = 3; i < e.contents.Count; i++)
                                {
                                    if (e.contents[i][0] == s)
                                    {
                                        temp.Append(e.parseRow(i));
                                    }
                                }
                                break;

                            case "arrayshell":
                                sp = s.Split('\\');
                                temp.Append("[");
                                e = null;
                                for (int b = 0; b < sp.Length; b++)
                                {
                                    e = ExcleToJson.ToJson(string.Format("{0}/{1}{2}", filePath.Substring(0, filePath.LastIndexOf('/')), names[line], excelSuffix), true);
                                    if (null == e)
                                    {
                                        break;
                                    }
                                    for (int i = 3; i < e.contents.Count; i++)
                                    {
                                        if (e.contents[i][0] == sp[b])
                                        {
                                            if (b == sp.Length - 1)
                                            {
                                                temp.Append(e.parseRow(i));
                                            }
                                            else
                                            {
                                                temp.Append(string.Format("{0},", e.parseRow(i)));
                                            }
                                        }
                                    }
                                }
                                temp.Append("]");
                                break;

                            default: break;
                            }
                            if (line != types.Count - 1)
                            {
                                temp.Append(",");
                            }
                            else
                            {
                                temp.Append("}");
                            }
                        }
                        return(temp.ToString());
                    }