首页 VIN车辆识别代码查询 VIN车辆识别代码查询示例代码 VIN查询[C#]

VIN查询示例代码C#

作者: 阅读数:1147 上传时间:2025-04-02

VIN查询

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

//await Vin.QueryAsync("LSVAL41Z882104202");
class Vin
{
    // 替换成你的AppKey
    private const string AppKey = "YOUR_APPKEY_HERE";

    public static async Task QueryAsync(string vin)
    {
        try
        {
            using (HttpClient client = new HttpClient())
            {
                // 构造请求URL
                string url = $"https://api.jisuapi.com/vin/query?appkey={AppKey}&vin={vin}";

                // 发送GET请求
                HttpResponseMessage response = await client.GetAsync(url);
                
                // 确保成功响应
                response.EnsureSuccessStatusCode();

                // 读取响应内容
                string responseBody = await response.Content.ReadAsStringAsync();
                JObject result = JObject.Parse(responseBody);

                // 处理API返回状态
                if ((int)result["status"] == 0)
                {
                    // 解析信息
					JToken data = result["result"];	
                    Console.WriteLine(data["manufacturer"]+" "+data["brand"]+" "+data["cartype"]);
					Console.WriteLine(data["name"]+" "+data["yeartype"]+" "+data["environmentalstandards"]);
					Console.WriteLine(data["comfuelconsumption"]+" "+data["engine"]+" "+data["gearbox"]);
					Console.WriteLine(data["drivemode"]+" "+data["carbody"]+" "+data["fronttiresize"]+" "+data["reartiresize"]+" "+data["vin"]);
					foreach (var item in data["carlist"])
                    {
                        Console.WriteLine($"{item["carid"]} {item["typename"]} {item["name"]}");
                    }
                }
                else
                {
                    Console.WriteLine($"查询失败:{result["status"]} {result["msg"]}");
                }
            }
        }
        catch (HttpRequestException ex)
        {
            Console.WriteLine($"请求异常:{ex.Message}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"发生错误:{ex.Message}");
        }
    }
	
	static async Task Main(string[] args)
    {
        //await QueryAsync("LSVAL41Z882104202");
    }
}