-1

I was working on my project and I've come across this error that makes me abit frustrated for no reason:

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

I have been looking for many ways to solve this even on this very website but none worked so far for C# and Xaml. I am attempting to get JSON files into UPF to look like GUI.

My Vehicle Class:

    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;
        }

    }

My Vehicle JSON:

    {
      "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?



1 Answers1

0

Look at the error message it's giving you. It says the unexpected character is 'V' at line 0 position 0. My guess is the data being passed is not actually the JSON data you think it is - perhaps it's some kind of string representation of a Vehicle (only guessing on that part from the 'V').

The best way to troubleshoot is throw your data being serialized into a local variable and set a break point right before you call the method to serialize. That way you can see exactly what is getting passed.

You may actually want to check out this question, you may be having a similar issue.

Aelarion
  • 397
  • 4
  • 11