Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过使用C从文本文件获取所有值,一次创建所有json文件#_C#_Dictionary_Foreach_Text Files_Keyvaluepair - Fatal编程技术网

C# 通过使用C从文本文件获取所有值,一次创建所有json文件#

C# 通过使用C从文本文件获取所有值,一次创建所有json文件#,c#,dictionary,foreach,text-files,keyvaluepair,C#,Dictionary,Foreach,Text Files,Keyvaluepair,我创建了一个长文本文件名POI.txt,它首先包含城市名称,然后放置该城市的名称。我的文本文件如下所示- Flensburg;Flensburger Brauerei;Flensburg station;Fachhochschule Flensburg;Flens-Arena;Duborg-Skolen;Nordertor Kiel;Walther Schücking Institute of International Law;Ferdinand Tönnies Society;Zoologi

我创建了一个长文本文件名POI.txt,它首先包含城市名称,然后放置该城市的名称。我的文本文件如下所示-

Flensburg;Flensburger Brauerei;Flensburg station;Fachhochschule Flensburg;Flens-Arena;Duborg-Skolen;Nordertor
Kiel;Walther Schücking Institute of International Law;Ferdinand Tönnies Society;Zoological Museum of Kiel University
Berlin;Battle of Berlin;Timeline of Berlin;Warschauer Straße;Berlin Brandenburger Tor station;Embassy of the United Kingdom, Berlin
and many many city.........
之后,我在Combobox1中保留城市名称,在Combox2中保留地名。因此,当一个城市出现在combobox 1中时,它会在第二个combobox中显示该城市的所有地方。我在第二个组合框后创建了一个按钮。我使用这个按钮创建一个位置的json文件

这是我为每个地方创建json的方法

public void ToJsonForLocation(string CityName,string PoiName)
    {

        var startPath = Application.StartupPath;
        string folderName = Path.Combine(startPath, "OnePoiJson");
        string SubfolderName = Path.Combine(folderName, CityName);
        System.IO.Directory.CreateDirectory(SubfolderName);
        string fileName = PoiName + ".json";

        var path = Path.Combine(SubfolderName, fileName);
        var Jpeg_File = new DirectoryInfo(startPath + @"\Image\" + CityName).GetFiles("*.jpg");

        POIData Poi=new POIData();
        Poi.Name = PoiName;
        Poi.Shorttext = new WikiShortText().GetShortText(PoiName);
        Poi.GeoCoordinates = GeosFromString(startPath + @"\Latitude Longitude\" + PoiName + ".txt");
        Poi.Images = new List<string> { Jpeg_File[0].Name };

        //Poi.Images =new List<string> {  string.Format("{0:X}.jpg", new WikiImage().GetImage(PoiName).Image.GetHashCode())};

        string json = JsonConvert.SerializeObject(Poi,Formatting.Indented);
        File.WriteAllText(path,json);
     }

现在我的问题是,在我的代码中,我需要单击第二个组合框上的每个位置,为该城市创建一个json文件。这需要花费太多的时间。我想一次创建所有文件。我知道我需要创建一个字典来实现这一点。但由于我对处理这种情况非常陌生,我想知道如何处理它

我需要单击第二个combobox上的每个位置,为该城市创建一个json文件
你是说现在你必须一次为comboBox2选择一个选项,并通过单击按钮分别创建每个json,但你希望能够从comboBox2中选择多个项目,一次生成所有项目?@Prix。准确地说。我希望,每当值出现在第二个combobox上时,它都会使用按钮click.OK一次创建所有文件,但您希望用户能够从combobox 2中选择哪些条目,或者您希望所有条目生成一个文件或包含所有所选条目的1文件@如果我在组合框1中选择一个像柏林这样的城市,我希望这一点。然后在组合框2中会出现Plac1、Place2、Place3。。等等。因此,将一次创建此位置的所有json文件。和我在Combobox 1中选择Munich一样,它将一次为该城市创建所有json文件。但值应该取决于Combobox 1
  private void JSON_Click(object sender, EventArgs e)
    {
            JSON_Output poi_Json = new JSON_Output();
            poi_Json.ToJsonForLocation(comboBox1.Text, comboBox2.Text);
    }