小编Chr*_*ine的帖子

在C#中读取和解析Json文件

我已经花了两天时间对代码样本等进行"最好的"工作,尝试将一个非常大的JSON文件读入c#中的数组中,以便稍后将其拆分为二维数组进行处理.

我遇到的问题是我找不到任何人做我想做的事情的例子.这意味着我只是想编写一些希望最好的代码.

我已经成功地完成了一些工作:

  • 读取文件Miss out headers并仅将值读入数组.
  • 在数组的每一行上放置一定数量的值.(所以我以后可以把它分成2d数组)

这是通过下面的代码完成的,但是在输入几行到数组后它会崩溃程序.这可能与文件大小有关.

// If the file extension was a jave file the following 
// load method will be use else it will move on to the 
// next else if statement
if (fileExtension == ".json") 
{
    int count = 0;
    int count2 = 0;
    int inOrOut = 0;
    int nRecords=1; 
    JsonTextReader reader = new JsonTextReader(new StreamReader(txtLoaction.Text));
    string[] rawData = new string[5];
    while (reader.Read())
    {
        if (reader.Value != null)
            if (inOrOut == 1)
            {
                if …
Run Code Online (Sandbox Code Playgroud)

c# parsing json large-files

207
推荐指数
9
解决办法
49万
查看次数

标签 统计

c# ×1

json ×1

large-files ×1

parsing ×1