static PrevisaoIPMA LerFicheiroPrevisao(int globalIdLocal) { String jsonString = null; using (StreamReader reader = new StreamReader(@"../../../data_forecast/" + globalIdLocal + ".json")) { jsonString = reader.ReadToEnd(); } PrevisaoIPMA obj = JsonSerializer.Deserialize <PrevisaoIPMA>(jsonString); return(obj); }
static void Main(string[] args) { Dictionary <int, string> dicLocais = LerLocais(@"../../../locais.csv"); //List<Detalhe> detalhe = new List<Detalhe>(); // Apenas para mostrar o conteúdo da estrutura dicinário... foreach (KeyValuePair <int, string> kv in dicLocais) { Console.WriteLine($"globalIdLocal= {kv.Key} cidade= {kv.Value}"); Detalhe detalhe = new Detalhe { globalIdLocal = kv.Key, cidade = kv.Value, }; File.WriteAllText(@"../../" + detalhe.globalIdLocal + "-detalhe.json", JsonConvert.SerializeObject(detalhe)); //XmlSerializer writer = new XmlSerializer(detalhe.GetType()); var path = @"../../" + detalhe.globalIdLocal + "-detalhe.xml"; //System.IO.FileStream file = System.IO.File.Create(path); //writer.Serialize(file, detalhe); using (var writer = new StreamWriter(path)) { XmlSerializer serializer = new XmlSerializer(detalhe.GetType()); serializer.Serialize(writer, detalhe); writer.Flush(); } // para cada linha do ficheiro CSV ... PrevisaoIPMA previsaoIPMA = LerFicheiroPrevisao(kv.Key); previsaoIPMA.local = kv.Value; } Console.ReadKey(); }