using System; using System.Net.Http; using System.Threading.Tasks; using Newtonsoft.Json.Linq; class VehicleLimit { private const string AppKey = "YOUR_APPKEY_HERE"; // 替换为实际的 appkey // 查询指定城市和日期的限行信息 public static async Task QueryAsync(string city, string date) { try { using var client = new HttpClient(); string url = $"https://api.jisuapi.com/vehiclelimit/query?appkey={AppKey}&city={city}&date={date}"; HttpResponseMessage response = await client.GetAsync(url); response.EnsureSuccessStatusCode(); string responseContent = await response.Content.ReadAsStringAsync(); JObject jsonarr = JObject.Parse(responseContent); int status = jsonarr["status"]?.ToObject() ?? -1; JObject? result = jsonarr["result"] as JObject; Console.WriteLine(result["time"]?.ToString() ?? ""); string timestr = ""; if (result["time"] is JArray timeArray) { foreach (var time in timeArray) { timestr += " " + (time?.ToString() ?? ""); } } Console.WriteLine($"{result["city"]?.ToString() ?? ""} {result["cityname"]?.ToString() ?? ""} {result["date"]?.ToString() ?? ""} {result["week"]?.ToString() ?? ""} {timestr} {result["numberrule"]?.ToString() ?? ""} {result["number"]?.ToString() ?? ""}"); Console.WriteLine(result["area"]?.ToString() ?? ""); Console.WriteLine(result["summary"]?.ToString() ?? ""); } catch (HttpRequestException ex) { Console.WriteLine($"请求出错: {ex.Message}"); } catch (Exception ex) { Console.WriteLine($"发生错误: {ex.Message}"); } } static async Task Main() { await VehicleLimit.CityAsync(); await VehicleLimit.QueryAsync("hangzhou", "2025-4-22"); } }
© 2015-2025 杭州极速互联科技有限公司 版权所有 浙ICP备17047587号-4 浙公网安备33010502005096 增值电信业务经营许可证:浙B2-20190875