我正在尝试更改http://localhost:5001/api/values路线,但程序卡在这个网址上。
我读过这个解决方案
如何更改 ASP.NET Core API 中的默认控制器和操作?
如何在 Asp.Net Core 2.x 中将 root 重定向到 swagger?
https://medium.com/quick-code/routing-in-asp-net-core-c433bff3f1a4
每个人都写同样的东西,但对我不起作用。
我的launchSetting.json
文件是
{ "$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54650",
"sslPort": 44382
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ShoppingBasketAPI": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试改变app.UseMvc();
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-2.2
这也行不通。它从哪里来api/values
?我想不通。 …
我正在尝试将Json数据解码到我的模型中。这是我的模特
struct Devices : Codable {
var id :String?
var description :String?
var status : Int?
Run Code Online (Sandbox Code Playgroud)
}
var heroes = Devices()
print(DeviceId)
let loginParam: [String: Any] = [
"id": DeviceId
]
let manager = Alamofire.SessionManager.default
manager.session.configuration.timeoutIntervalForRequest = 5
manager.request("http://13.13.13.004/website/api/Customer/DeviceControl", method: .post , parameters: loginParam, encoding: JSONEncoding.prettyPrinted)
.responseData { response in
let json = response.data
do{
let decoder = JSONDecoder()
//using the array to put values
heroes = try decoder.decode(Devices.self, from: json!)
}catch let err{
print(err)
}
Run Code Online (Sandbox Code Playgroud)
该代码不会进入catch块。但是,英雄价值观归零。什么时候 ?尝试使用NsDictionary 其给定结果。