/// <summary> /// The ConvertTourDataTableTOJson method converts a filled data table into a /// JSON string to be saved as a text file by the caller. /// </summary> public string CovertCategoryDataTableToJSON(DataTable parFilledDataTable) { //Convert DataTable to List collection of Transfer Objects List<TO_POI_Cateogry> items = new List<TO_POI_Cateogry>(); foreach (DataRow row in parFilledDataTable.Rows) { string ID = Convert.ToString(row["Category_Code"]); string title = Convert.ToString(row["Category_Name"]); string fileName = "Category_" + ID + ".js"; TO_POI_Cateogry itemTransferObject = new TO_POI_Cateogry(ID, title, fileName); items.Add(itemTransferObject); } //Create JSON-formatted string JavaScriptSerializer oSerializer = new JavaScriptSerializer(); string JSONString = oSerializer.Serialize(items); //add in return JSONString when taking out PrettyPrint return JSONString; ////Format json string //string formattedJSONString = JsonFormatter.PrettyPrint(JSONString); // return formattedJSONString; }
/// <summary> /// The ConvertTourDataTableTOJson method converts a filled data table into a /// JSON string to be saved as a text file by the caller. /// </summary> public string CovertCategoryDataTableToJSON(DataTable parFilledDataTable) { //Convert DataTable to List collection of Transfer Objects List <TO_POI_Cateogry> items = new List <TO_POI_Cateogry>(); foreach (DataRow row in parFilledDataTable.Rows) { string ID = Convert.ToString(row["Category_Code"]); string title = Convert.ToString(row["Category_Name"]); string fileName = "Category_" + ID + ".js"; TO_POI_Cateogry itemTransferObject = new TO_POI_Cateogry(ID, title, fileName); items.Add(itemTransferObject); } //Create JSON-formatted string JavaScriptSerializer oSerializer = new JavaScriptSerializer(); string JSONString = oSerializer.Serialize(items); //add in return JSONString when taking out PrettyPrint return(JSONString); ////Format json string //string formattedJSONString = JsonFormatter.PrettyPrint(JSONString); // return formattedJSONString; }