Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.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# Foreach循环在第10次迭代后返回null_C#_Asp.net Mvc_Google Api_Asp.net Core 2.0_Google Books - Fatal编程技术网

C# Foreach循环在第10次迭代后返回null

C# Foreach循环在第10次迭代后返回null,c#,asp.net-mvc,google-api,asp.net-core-2.0,google-books,C#,Asp.net Mvc,Google Api,Asp.net Core 2.0,Google Books,我通过.NET使用了谷歌图书Api。和MVC核心2。我检索一个IEnumerable数据,通过一个简单的foreach循环迭代,我将每本书分配给列表中的一个book对象。 这是我定制的代码 这很奇怪,因为调试器显示请求成功执行,我得到了结果 可能出了什么问题? 提前感谢。其中一个属性值为null。页面计数。调试器停止时,请检查当前项是否包含您尝试分配/使用的每个属性的数据 此外,InnerException可能包含失败属性的名称。您能否将参数传递给该方法,这样我们可以确保查看的内容与您的完全相

我通过.NET使用了谷歌图书Api。和MVC核心2。我检索一个IEnumerable数据,通过一个简单的foreach循环迭代,我将每本书分配给列表中的一个book对象。 这是我定制的代码

这很奇怪,因为调试器显示请求成功执行,我得到了结果

可能出了什么问题?
提前感谢。

其中一个属性值为
null
。页面计数。调试器停止时,请检查当前项是否包含您尝试分配/使用的每个属性的数据


此外,InnerException可能包含失败属性的名称。

您能否将参数传递给该方法,这样我们可以确保查看的内容与您的完全相同。我的主要参数是一个类似“subject=adventure”的字符串,偏移量是集合中开始列表的位置的整数,整数计数是我希望获取的最大结果(api允许40)
        public IEnumerable<Book> GetBooks(string query, int offset, int count)
    {

        var queryList = _booksService.Volumes.List(query);
        queryList.MaxResults = count;
        queryList.StartIndex = offset;
        var result = queryList.Execute();

        if (result != null) { 

        var books = result.Items.Select(b => new Book
        {
           // id = b.Id,
            title = b.VolumeInfo.Title,
            subtitle = b.VolumeInfo.Subtitle,
            authors = string.Join(",",b.VolumeInfo.Authors),
            publisher = b.VolumeInfo.Publisher,
            publishedDate = b.VolumeInfo.PublishedDate,
            description = b.VolumeInfo.Description,
            pageCount = (int)b.VolumeInfo.PageCount,
            category = string.Join(",",b.VolumeInfo.Categories),               
            maturityRating = b.VolumeInfo.MaturityRating,
            language = b.VolumeInfo.Language,
            smallThumbnail = b.VolumeInfo.ImageLinks.SmallThumbnail,
            thumbnail = b.VolumeInfo.ImageLinks.Thumbnail

        }).ToList();

        return books;

        }
        else
        {
            return null;
        }
    }
var books = result.Items.Select(b => new Book