亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Json 中返回一些列表的問題:ASP.NET Core

在 Json 中返回一些列表的問題:ASP.NET Core

C#
蠱毒傳說 2022-01-09 15:32:16
我正在創建一個從 MySql 數據庫返回一些結果的 API。我有一個包含 2 行和一些字段的表。查詢的主要因素是一個名為Title. 應用程序應根據“標題”字段返回結果。在titles這兩個記錄是甜街和甜街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; }        }    }}然后我選擇前面提到的 2 行并以 JSON 格式返回結果:    [Route("IMES/api/GET/search/t={movieTitle}")]    [HttpGet]    public IActionResult MovieSearch(string movieTitle)    {        string searchKeyword = movieTitle.Replace("%20", " ");        //Try to connect to the database        try        {            }        }當我瀏覽時.../IMES/api/GET/search/t=sweet,我只得到第一行數據,第二行沒有包含關鍵字的第二個列表sweet。我想在 JSON 的單獨列表中獲取兩行的數據。任何人都可以幫忙嗎?注意:我已經在 SQL Studio 中嘗試過查詢,我收到了兩條記錄。所以我確定那 2 行!
查看完整描述

1 回答

?
呼如林

TA貢獻1798條經驗 獲得超3個贊

您正在從 while 循環返回


while(){

    retun Ok(response);

}

,所以在添加第一項后返回。將其移出 while 循環


while(){

 //do stuff

}

string response = JsonConvert.SerializeObject(baseResponse);

return Ok(response);


查看完整回答
反對 回復 2022-01-09
  • 1 回答
  • 0 關注
  • 175 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號