Deserialize an Object from JSON API - Unexpected character encountered while parsing value: {. Path '[0].produced_weight', line 1, position 295

Viewed 48

Im retrieving JSON format data from an API URL like: https://example.help/api/a?start_date=2022-09-01&end_date=2022-09-13&apikey=123 And i'm using to get the data:

public string Get(string url, string json, Contexto oContexto)
    {
        try
        {

            var client = new RestClient(url);
            var request = new RestRequest(Method.GET);
            IRestResponse response = client.Execute(request);
            return response.Content;
        }
        catch (Exception oExcepcion)
        {
            ErrorControl oErrorControl = new ErrorControl();
            oErrorControl.RecordErrorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, oContexto.Request, oContexto.UserIdentity, oExcepcion);
            return string.Empty;
        }
    }

And when im trying to deserialize the data with

oListTransparency = JsonConvert.DeserializeObject<List<ReportTransparency>>(datos);

I'm getting this error Unexpected character encountered while parsing value: {. Path '[0].produced_weight', line 1, position 295. The variable datos is an String with the text format of the JSON

The JSON looks like this:

[{"ico_id":"03-0178-905-22-H","ico_status":"approved_qa","country":"COL","contract_id":"C-1546","contract_type":"differential","quality":"RTB","grade":600,"certification":null,"customer_name":"LA COLOMBE TORREFACTION","mark":"Huila","units":205,"production_number":"OTT-1804","produced_weight":{"value":"950.0","unit_of_measurement":"kg"},"approval_date":"2022-09-03","dry_parchment_costs":{"per_kg":"13511.92","total_kg":"12836324.0","per_carga":"1688990.0","currency":"COP"},"average_purchase_price":{"value":"21364.2","currency":"COP"},"assigned_coffees":[{"lotset_id":"COL-SET-3398","lotset_local_id":"PAI-SET-117","purchase_weight":{"value":"2982.0","unit_of_measurement":"kg"},"lots":[{"lot_id":"PAI-LOT-518","lot_main_id":"COL-LOT-17437","assigned_weight":{"value":"172.03","unit_of_measurement":"kg"},"producer_name":"JOSE LOPEZ","purchase_weight":{"value":"513.0","unit_of_measurement":"kg"}},{"lot_id":"PAI-LOT-556","lot_main_id":"COL-LOT-17964","assigned_weight":{"value":"207.58","unit_of_measurement":"kg"},"producer_name":"EDINSON CHAVARRO","purchase_weight":{"value":"619.0","unit_of_measurement":"kg"}},{"lot_id":"PAI-LOT-525","lot_main_id":"COL-LOT-17659","assigned_weight":{"value":"40.58","unit_of_measurement":"kg"},"producer_name":"OLIVER CABRERA","purchase_weight":{"value":"121.0","unit_of_measurement":"kg"}},{"lot_id":"PAI-LOT-546","lot_main_id":"COL-LOT-17900","assigned_weight":{"value":"75.12","unit_of_measurement":"kg"},"producer_name":"CESAR CARDOSO","purchase_weight":{"value":"224.0","unit_of_measurement":"kg"}},{"lot_id":"PAI-LOT-555","lot_main_id":"COL-LOT-17963","assigned_weight":{"value":"252.85","unit_of_measurement":"kg"},"producer_name":"EDINSON CHAVARRO","purchase_weight":{"value":"754.0","unit_of_measurement":"kg"}},{"lot_id":"PAI-LOT-552","lot_main_id":"COL-LOT-17958","assigned_weight":{"value":"251.84","unit_of_measurement":"kg"},"producer_name":"EDINSON CHAVARRO","purchase_weight":{"value":"751.0","unit_of_measurement":"kg"}}],"assigned_weight":{"value":"1000.0","unit_of_measurement":"kg"}},{"lot_id":"POP-LOT-85","producer_name":"JOSE CANO","purchase_price":{"value":"21364.2","currency":"COP"},"purchase_weight":{"value":"268.0","unit_of_measurement":"kg"},"assigned_weight":{"value":"266.2","unit_of_measurement":"kg"}}],"exchange_rate":{"value":"4480.5","target_currency":"COP"},"additional_greens":[]}]

The class fr the ReportTransparency

public class ReportTransparency
{
    public string ico_id { get; set; }
    public string ico_status { get; set; }
    public string country { get; set; }
    public string contract_id { get; set; }
    public string contract_type { get; set; }
    public string quality { get; set; }
    public int grade { get; set; }
    public string certification { get; set; }
    public string customer_name { get; set; }
    public string mark { get; set; }
    public int units { get; set; }
    public string produced_weight { get; set; }
    public string unit_of_measurement { get; set; }
    public string approval_date { get; set; }
    public ReportDryParchmentCosts dry_parchment_costs { get; set; }
    public List<ReportAssignedCoffee> assigned_coffees { get; set; }
    public List<ReportAdditionalGreen> additional_greens { get; set; }
    
    //NEW
    public string production_number { get; set; }
    public ReportAveragePurchasePrice average_purchase_price { get; set; }
    public ReportExchangeRate exchange_rate { get; set; }

}

And the others

public class ReportAssignedCoffee
{
    public string lot_id { get; set; }
    public string producer_name { get; set; }
    public string assigned_weight { get; set; }
    public string unit_of_measurement { get; set; }
    public string lotset_id { get; set; }
    public string lotset_local_id { get; set; }
    public string milling_output_id { get; set; }
    public List<ReportTransparency_Lot> lots { get; set; }
    //NEW
    public ReportAveragePurchasePrice purchase_price { get; set; }
    public ReportPurchaseWeight purchase_weight { get; set; }
}

And in that way with all the subclasses Thank you!!

0 Answers
Related