Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用SSIS脚本组件读取JSON文件_C#_Json_Ssis_Nested_Json.net - Fatal编程技术网

C# 使用SSIS脚本组件读取JSON文件

C# 使用SSIS脚本组件读取JSON文件,c#,json,ssis,nested,json.net,C#,Json,Ssis,Nested,Json.net,我正在尝试使用SSIS(JSON.net库中的脚本组件和C#代码)读取JSON文件。我的JSON文件看起来很复杂,而且我对C#代码还不熟悉。下面是关于我的JSON文件的示例 { “产品”:{ “col1”:“xyz”, “col2”:“ryx” }, “样本”:[{ “col3”:“读取”, “col4”:“写入” }, { “col3”:“读取”, “col4”:“更新” } ] } 任何帮助都将不胜感激 您需要如下所示的类结构: public class Product { pub

我正在尝试使用SSIS(JSON.net库中的脚本组件和C#代码)读取JSON文件。我的JSON文件看起来很复杂,而且我对C#代码还不熟悉。下面是关于我的JSON文件的示例

{
“产品”:{
“col1”:“xyz”,
“col2”:“ryx”
},
“样本”:[{
“col3”:“读取”,
“col4”:“写入”
},
{
“col3”:“读取”,
“col4”:“更新”
}
]
}

任何帮助都将不胜感激

您需要如下所示的类结构:

public class Product
{
    public string col1 { get; set; }
    public string col2 { get; set; }
}

public class Sample
{
    public string col3 { get; set; }
    public string col4 { get; set; }
}

public class Root
{
    public Product Product { get; set; }

    public Sample[] Samples { get; set; }
}
下面是您可以用来读取JSON的代码

注意:sample.json文件包含json响应

public static void Main(string[] args)
{

        using (var stream = new StreamReader("sample.json"))
        {

            var sample = JsonConvert.DeserializeObject<Root>(stream.ReadToEnd());
            Console.WriteLine(sample.Product.col1);
            Console.WriteLine(sample.Product.col2);
            foreach (var t in sample.Samples)
            {
                Console.WriteLine(t.col3);
                Console.WriteLine(t.col4);
            }
        }

        Console.Read();
}
publicstaticvoidmain(字符串[]args)
{
使用(var stream=newstreamreader(“sample.json”))
{
var sample=JsonConvert.DeserializeObject(stream.ReadToEnd());
Console.WriteLine(sample.Product.col1);
Console.WriteLine(sample.Product.col2);
foreach(sample.Samples中的var t)
{
控制台写入线(t.col3);
控制台写入线(t.col4);
}
}
Console.Read();
}

谢谢Sameer。让我尝试此操作无法加载文件或程序集“Newtonsoft.Json,Version=6.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6eed”或其依赖项之一。系统找不到指定的文件。--我在执行SSIS包时遇到此错误。我尚未解决此问题。但这给了我一个很好的画面。肯定会解决吗?如果你觉得答案有用,就把它标出来。