Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.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# 如何从JSON读取列表 公共类事务 { 公共字符串Day_of_Week{get;set;} 公共字符串月份{get;set;} 公共字符串Post{get;set;} 从{get;set;}发送的公共int_ 公共整数{get;set;} 公共字符串时间{get;set;} } 公共类根 { 公共int发送到{get;set;} 公共整数总计收到的值{get;set;} 公共列表事务{get;set;} } 静态void Main(字符串[]参数) { 使用(WebClient wc=new WebClient()) { var json=wc.DownloadString(“xxxxxxx”); var m=JsonConvert.DeserializeObject(json); foreach(以m为单位的var项目) { Console.WriteLine(项目事务); } } }_C#_Json.net - Fatal编程技术网

C# 如何从JSON读取列表 公共类事务 { 公共字符串Day_of_Week{get;set;} 公共字符串月份{get;set;} 公共字符串Post{get;set;} 从{get;set;}发送的公共int_ 公共整数{get;set;} 公共字符串时间{get;set;} } 公共类根 { 公共int发送到{get;set;} 公共整数总计收到的值{get;set;} 公共列表事务{get;set;} } 静态void Main(字符串[]参数) { 使用(WebClient wc=new WebClient()) { var json=wc.DownloadString(“xxxxxxx”); var m=JsonConvert.DeserializeObject(json); foreach(以m为单位的var项目) { Console.WriteLine(项目事务); } } }

C# 如何从JSON读取列表 公共类事务 { 公共字符串Day_of_Week{get;set;} 公共字符串月份{get;set;} 公共字符串Post{get;set;} 从{get;set;}发送的公共int_ 公共整数{get;set;} 公共字符串时间{get;set;} } 公共类根 { 公共int发送到{get;set;} 公共整数总计收到的值{get;set;} 公共列表事务{get;set;} } 静态void Main(字符串[]参数) { 使用(WebClient wc=new WebClient()) { var json=wc.DownloadString(“xxxxxxx”); var m=JsonConvert.DeserializeObject(json); foreach(以m为单位的var项目) { Console.WriteLine(项目事务); } } },c#,json.net,C#,Json.net,我想打印“交易”的内容,但我真的不明白为什么我不能访问交易项目(星期几、月份、帖子等),有什么想法吗 “发送到”和“收到的总功绩”都正确打印。您需要使用一个以上的foreach循环来完成此操作 public class Transaction { public string Day_of_Week { get; set; } public string Month { get; set; } public string Post { ge

我想打印“交易”的内容,但我真的不明白为什么我不能访问交易项目(星期几、月份、帖子等),有什么想法吗


“发送到”和“收到的总功绩”都正确打印。

您需要使用一个以上的
foreach
循环来完成此操作

public  class Transaction
    {
        public string Day_of_Week { get; set; }
        public string Month { get; set; }
        public string Post { get; set; }
        public int Sent_from { get; set; }
        public int number_of_merit { get; set; }
        public string time { get; set; }

    }

    public class Root
    {
        public int Sent_to { get; set; }
        public int Total_Received_Merit { get; set; }
        public  List<Transaction> Transactions { get; set; }

    }

    static void Main(string[] args)
    {
       
        using (WebClient wc = new WebClient())
        {
        var  json = wc.DownloadString("xxxxxxx"); 
        var m = JsonConvert.DeserializeObject<List<Root>>(json);

       foreach (var item in m )
       {
           Console.WriteLine(item.Transactions);
       }
        }
       


    }

您可以添加示例json吗?还有
项。事务
是一个
列表
,因此您需要另一个
foreach
(例如)。@guruston完成了,谢谢@CSharpdocsz很乐意帮忙)
            foreach (var item in m)
            {
                foreach (var tran in item.Transactions)
                {
                    Console.WriteLine(tran.Month);
                }
            }