本文整理汇总了C#中JsonArray.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# JsonArray.ToArray方法的具体用法?C# JsonArray.ToArray怎么用?C# JsonArray.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonArray
的用法示例。
在下文中一共展示了JsonArray.ToArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadExcelFile
public void ReadExcelFile()
{
int colNameAt = 0;
int rowCount = 0;
List<string> title = new List<string>();
JsonArray arrays = new JsonArray();
var fileName = "BYOVArtistMasterList.xlsx";
var filePath = HttpContext.Current.Server.MapPath("~/File/Upload/") + fileName;
var stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
// Want to be able to handle .xls or .xlsx file formats
var excelReader = filePath.Contains(".xlsx")
? ExcelReaderFactory.CreateOpenXmlReader(stream)
: ExcelReaderFactory.CreateBinaryReader(stream);
excelReader.IsFirstRowAsColumnNames = true;
excelReader.Read(); //skip first row
while (excelReader.Read())
{
bool hasData = true;
int count = 0;
JsonObject obj = new JsonObject();
while (hasData == true)
{
string data = excelReader.GetString(count);
if (!string.IsNullOrEmpty(data))
{
data = data.Trim();
if (rowCount == colNameAt)
{
data = data.Replace("/", "");
data = data.Replace(" ", "_");
data = string.Format("{0}_{1}", data, count);
title.Add(data);
}
else
{
string key = title.ElementAt(count);
obj.Add(key, data);
}
}
else
{
hasData = false;
}
count++;
}
if ((rowCount > colNameAt) && (obj.Keys.Count() > 0))
{
arrays.Add(obj);
}
rowCount++;
}
excelReader.Close();
try
{
fileName = "BYOVArtistMasterList.json";
filePath = HttpContext.Current.Server.MapPath("~/File/Download/") + fileName;
string json = JsonConvert.SerializeObject(arrays.ToArray());
//write string to file
System.IO.File.WriteAllText(filePath, json);
}
catch (Exception)
{
}
}