Beispiel #1
0
        public static string SortCSVFileOnNumbersAndWriteInJsonAndReturnData(string filePath, string jsonFilepath, string key)
        {
            string        re = File.ReadAllText(filePath);
            StringBuilder sb = new StringBuilder();

            using (var p = ChoCSVReader.LoadText(re)
                           .WithFirstLineHeader()
                   )
            {
                using (var w = new ChoJSONWriter(sb))
                    w.Write(p);
            }
            File.WriteAllText(jsonFilepath, sb.ToString());
            JArray arr     = CSVOperations.SortJsonBasedOnKeyAndValueIsNumber(jsonFilepath, key);
            var    jsonArr = JsonConvert.SerializeObject(arr, Formatting.Indented);

            File.WriteAllText(jsonFilepath, jsonArr);

            return(CSVOperations.RetriveLastDataOnKey(jsonFilepath, key));
        }
Beispiel #2
0
        /// <summary>
        ///sorting the state for population,density and area
        /// </summary>
        /// <param name="path"> State Code data path </param>
        /// <param name="jsonFilepath"> Delimiter </param>
        /// <param name="key"> Header </param>
        /// <returns> sorting the state for population,density and area </returns>
        public static string SortCSVInJsonAndReturnData(string path, string jsonFilepath, string key)
        {
            //create a object to read file
            string        csvfile = File.ReadAllText(path);
            StringBuilder json    = new StringBuilder();

            //read a csv file
            using (var p = ChoCSVReader.LoadText(csvfile)
                           .WithFirstLineHeader()
                   )
            {
                //write json file
                using (var w = new ChoJSONWriter(json))
                    w.Write(p);
            }
            File.WriteAllText(jsonFilepath, json.ToString());
            JArray arr = CSVOperations.SortJsonBasedOnKeyAndValueIsNumber(jsonFilepath, key);
            //convert into json format
            var jsonArr = JsonConvert.SerializeObject(arr, Formatting.Indented);

            File.WriteAllText(jsonFilepath, jsonArr);

            return(CSVOperations.RetriveLastDataOnKey(jsonFilepath, key));
        }