我目前正在尝试自己学习一些后端,并且在尝试通过我的ASP.NET Core Web API进行第三方API调用时遇到了一些问题。我试图从TMDB API get获取电影信息,但尽管我设法以字符串的形式获取信息,但当我尝试反序列化时,它会导致空数组。
我看了几个视频,解释了进行第三方API调用的不同方法,最后使用了HttpClient方法,因为我没有建立一个类来将数据保存到中,所以我将其反序列化为一个动态对象。
namespace MoviesRouletteReactApp.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class MovieController : ControllerBase
{
[HttpGet]
//private const string API_KEY = ;
public async Task<IActionResult> GetMoviesList()
{
var movie = new List<Result>();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://api.themoviedb.org/3/movie/now_playing?language=en-US&page=1");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER TOKEN");
var response = await client.GetAsync(client.BaseAddress);
if (response.IsSuccessStatusCode)
{
var stringResponse = response.Content.ReadAsStringAsync().Result;
var dynamicResult = JsonConvert.DeserializeObject<dynamic>(stringResponse);
return Ok(dynamicResult.results);
}
else
{
throw new HttpRequestException(response.ReasonPhrase);
}
}
}
}
}
这就是我在Swagger中尝试执行get请求时得到的结果:
[
[
[
[]
],
[
[]
],
[
[
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
[
[
[]
],
[
[]
],
[
[
[],
[],
[]
]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
]
]
我目前的知识并不丰富,而且主要是通过试错来学习,所以欢迎任何形式的反馈。