Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.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:ASP.NET核心中的某些列表时出现问题_C#_Asp.net_Json_Web Services_Asp.net Web Api - Fatal编程技术网

C# 返回Json:ASP.NET核心中的某些列表时出现问题

C# 返回Json:ASP.NET核心中的某些列表时出现问题,c#,asp.net,json,web-services,asp.net-web-api,C#,Asp.net,Json,Web Services,Asp.net Web Api,我正在创建一个API,它从MySql数据库返回一些结果。我有一个表,包括两行和一些字段。查询的主要因素是一个名为Title的字段。应用程序应根据“标题”字段返回结果。这两条记录的标题是甜街和甜街2 为了将结果作为JSON返回,我创建了一个类: using System.Collections.Generic; namespace IMES_Backend.Controllers { internal class Movie { public class BaseR

我正在创建一个API,它从MySql数据库返回一些结果。我有一个表,包括两行和一些字段。查询的主要因素是一个名为
Title
的字段。应用程序应根据“标题”字段返回结果。这两条记录的
标题是甜街甜街2

为了将结果作为JSON返回,我创建了一个类:

using System.Collections.Generic;
namespace IMES_Backend.Controllers
{
    internal class Movie
    {
        public class BaseResponse
        {
            public List<Item> search { get; set; } = new List<Item>();
            public bool response { get; set; }

        }

        public class Item
        {
            public string title { get; set; }
            public string year { get; set; }
            public string released { get; set; }
            public string runTime { get; set; }
            public string genre { get; set; }
            public string director { get; set; }
            public string writer { get; set; }
            public string actors { get; set; }
            public string language { get; set; }
            public string country { get; set; }
            public string awards { get; set; }
            public string poster { get; set; }
            public string imdbScore { get; set; }
            public string production { get; set; }
            public string dl480p { get; set; }
            public string dl720p { get; set; }
            public string dl1080p { get; set; }
            public string subtitleLink { get; set; }
            public string dubLink { get; set; }
            public string description { get; set; }
            public string state { get; set; }

        }
    }
}
当我浏览
../IMES/api/GET/search/t=sweet
时,我只获取第一行数据,第二行没有包含关键字
sweet
的第二个列表

我想在JSON中的分隔列表中获取这两行的数据。 有人能帮忙吗

注意:我在sqlstudio中尝试了这个查询,并收到了两条记录。所以我敢肯定这两排


您正在从while循环返回

while(){
    retun Ok(response);
}
while(){
 //do stuff
}
string response = JsonConvert.SerializeObject(baseResponse);
return Ok(response);
,因此在添加第一项后返回。 将其移出while循环

while(){
    retun Ok(response);
}
while(){
 //do stuff
}
string response = JsonConvert.SerializeObject(baseResponse);
return Ok(response);

谢谢你的回答!这很有效。你能指定我如何命名这些名单吗?例如,我想将列表一个命名为'Item1',第二个命名为'Item2',我会创建一个字典字典,其中字符串是guid或其他('Item1','Item2')P.S.如果答案有效,请您选择它作为答案(按勾选):)也,我建议使用参数化SQL-任何人都可以使用当前设置删除您的数据库!