有没有办法防止在从JSON解析为C#和XAML错误时遇到意外字符?

有没有办法防止在从JSON解析为C#和XAML错误时遇到意外字符?,c#,json,wpf,xaml,data-binding,C#,Json,Wpf,Xaml,Data Binding,我在做我的项目,我遇到了这个错误,让我有点无缘无故地沮丧: [问题][1] [1]: https://i.stack.imgur.com/9Ajtn.png 我一直在寻找很多方法来解决这个问题,即使是在这个网站上,但到目前为止,没有一种方法对C#和Xaml有效。我试图将JSON文件导入UPF,使其看起来像GUI 我的车辆类别: public class Vehicle { [JsonPropertyName("make")] p

我在做我的项目,我遇到了这个错误,让我有点无缘无故地沮丧:

[问题][1] [1]: https://i.stack.imgur.com/9Ajtn.png

我一直在寻找很多方法来解决这个问题,即使是在这个网站上,但到目前为止,没有一种方法对C#和Xaml有效。我试图将JSON文件导入UPF,使其看起来像GUI

我的车辆类别:

    public class Vehicle
    {
        [JsonPropertyName("make")]
        public string Make { get; set; }

        [JsonPropertyName("model")]
        public string Model { get; set; }

        [JsonPropertyName("VIN")]
        public string VIN { get; set; }

        [JsonPropertyName("CarType")]
        public string CarType { get; set; }

        [JsonPropertyName("Seatingcapacity")]
        public int Seatingcapacity { get; set; }

        [JsonPropertyName("DateObtained")]
        public string DateObtained { get; set; }

        [JsonPropertyName("NumOfMiles")]
        public int NumOfMiles { get; set; }

        [JsonPropertyName("InspectionNum")]
        public int InspectionNum { get; set; }

        [JsonPropertyName("InspectionTech")]
        public string InspectionTech { get; set; }

        [JsonPropertyName("InspectionDate")]
        public string InspectionDate { get; set; }

        [JsonPropertyName("InspectIssues")]
        public string InspectIssues { get; set; }

        [JsonPropertyName("RepairDiscard")]
        public string RepairDiscard { get; set; }

        [JsonPropertyName("EstPrice")]
        public int EstPrice { get; set; }

        [JsonPropertyName("EstimatedBy")]
        public string EstimatedBy { get; set; }

        [JsonPropertyName("EstimatedDate")]
        public string EstimatedDate { get; set; }

        [JsonPropertyName("SalePrice")]
        public int SalePrice { get; set; }

        [JsonPropertyName("SalesPerson")]
        public string SalesPerson { get; set; }

        [JsonPropertyName("SalesDate")]
        public string SalesDate { get; set; }

        [JsonPropertyName("NegotiatedPrice")]
        public string NegotiatedPrice { get; set; }

        [JsonPropertyName("NegotiatedPriceApproved")]
        public string NegotiatedPriceApproved { get; set; }
    }

    public class Root
    {
        [JsonPropertyName("Vehicle")]
        public List<Vehicle> Vehicle { get; set; }
    }
    public class VehicleManager
    { 

        public static async Task<Root> GetVehicles()
        {
            string target = "Vechile.json";

            Root vehicleJson = JsonConvert.DeserializeObject<Root>(target);

            return vehicleJson;
        }

    }

看看它给你的错误信息。它表示第0行位置0处的意外字符为“V”。我的猜测是,传递的数据实际上并不是您认为的JSON数据——可能是
车辆的某种字符串表示形式(仅从“V”中猜测该部分)

解决问题的最佳方法是将要序列化的数据放入局部变量,并在调用方法进行序列化之前设置断点。这样你就可以准确地看到通过了什么

你可能真的想退房,你可能有类似的问题

    {
      "make": "Audi",
      "model": "A4",
      "vin": "1B4HR28N41F524347",
      "carType": "Sedan",
      "Seatingcapacity": 4,
      "DateObtained": "05/15/2010",
      "NumOfMiles": 434567,
      "InspectionNum": 312345,
      "InspectionTech": "Windows",
      "InspectionDate": "06/05/2016",
      "InspectIssues": "No Issue",
      "RepairDiscard": "No Discard",
      "EstPrice": 700000,
      "EstimatedBy": "Sannaha Vahanna",
      "EstimatedDate": "04/27/2010",
      "SalePrice": 500000,
      "SalesPerson": "Sannaha Vahnna",
      "SalesDate": "05/15/2010",
      "NegotiatedPrice": "$45,000",
      "NegotiatedPriceApproved": "Sannaha Vahnna"
    }
}```
As well, my C#

```public sealed partial class MainPage : Page
    {

        public MainPage()
        {
           var Vehicles =  VehicleManager.GetVehicles();
            this.InitializeComponent();
        }

        private void VehicleGUI_ItemClick(object sender, ItemClickEventArgs e)
        {
            var vehicle= (Vehicle)e.ClickedItem;
            this.Frame.Navigate(typeof(VehicleDetails), vehicle);

        }

    }```

What to do?