Ошибка при десериализации json

I need to convert JSON data that I get from a REST API and convert them to CSV for some analytic. The problem is that the JSON data do not necessarily follow the same content, so I can’t define a type for mapping. This has become a challenge that is taking too much of my time. I have already created some code, but of course it is not working as it throws exception on this line

var data = JsonConvert.DeserializeObject<List<object>>(jsonData);

The error is:

Additional information: Cannot deserialize the current JSON object
(e.g. {«name»:»value»}) into type
‘System.Collections.Generic.List`1[System.Object]’ because the type
requires a JSON array (e.g. [1,2,3]) to deserialize correctly.

To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.

Path ‘data’, line 2, position 10.

please let me know what I can do to get this going.

A sample of data would be like this, the fields of data can change very often, for example a new field can be added the next day, so I don’t have the liberty to create a .Net class to map the data.

{
  "data": [
    {
      "ID": "5367ab140026875f70677ab277501bfa",
      "name": "Happiness Initiatives - Flow of Communication/Process & Efficiency",
      "objCode": "PROJ",
      "percentComplete": 100.0,
      "plannedCompletionDate": "2014-08-22T17:00:00:000-0400",
      "plannedStartDate": "2014-05-05T09:00:00:000-0400",
      "priority": 1,
      "projectedCompletionDate": "2014-12-05T08:10:21:555-0500",
      "status": "CPL"
    },
    {
      "ID": "555f452900c8b845238716dd033cf71b",
      "name": "UX Personalization Think Tank and Product Strategy",
      "objCode": "PROJ",
      "percentComplete": 0.0,
      "plannedCompletionDate": "2015-12-01T09:00:00:000-0500",
      "plannedStartDate": "2015-05-22T09:00:00:000-0400",
      "priority": 1,
      "projectedCompletionDate": "2016-01-04T09:00:00:000-0500",
      "status": "APR"
    },
    {
      "ID": "528b92020051ab208aef09a4740b1fe9",
      "name": "SCL Health System - full Sitecore implementation (Task groups with SOW totals in Planned hours - do not bill time here)",
      "objCode": "PROJ",
      "percentComplete": 100.0,
      "plannedCompletionDate": "2016-04-08T17:00:00:000-0400",
      "plannedStartDate": "2013-11-04T09:00:00:000-0500",
      "priority": 1,
      "projectedCompletionDate": "2013-12-12T22:30:00:000-0500",
      "status": "CPL"
    }
 ]
}



namespace BusinessLogic
{
    public class JsonToCsv
    {

       public string ToCsv(string jsonData, string datasetName)
       {
          var data = JsonConvert.DeserializeObject<List<object>>(jsonData);
          DataTable table = ToDataTable(data); 
          StringBuilder result = new StringBuilder();

            for (int i = 0; i < table.Columns.Count; i++)
            {
                result.Append(table.Columns[i].ColumnName);
                result.Append(i == table.Columns.Count - 1 ? "\n" : ",");
            }

            foreach (DataRow row in table.Rows)
            {
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    result.Append(row[i].ToString());
                    result.Append(i == table.Columns.Count - 1 ? "\n" : ",");
                }
            }

            return result.ToString().TrimEnd(new char[] {'\r', '\n'});

        }

        private DataTable ToDataTable<T>( IList<T> data )
            {
            PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));
            DataTable table = new DataTable();
            for (int i = 0 ; i < props.Count ; i++)
                {
                PropertyDescriptor prop = props[i];
                table.Columns.Add(prop.Name, prop.PropertyType);
                }

            object[] values = new object[props.Count];
            foreach (T item in data)
                {
                for (int i = 0 ; i < values.Length ; i++)
                    {
                    values[i] = props[i].GetValue(item);
                    }

                table.Rows.Add(values);
                }

            return table;
            }


        }
}

Здравствуйте.

Имею вот такую JSON строку:

{"id":"3","companies_name":"{EQ\r\n"}
{"id":"6","companies_name":"testName Company"}
{"id":"7","companies_name":"testName Company324324"}
{"id":"8","companies_name":"testName Company"}
{"id":"9","companies_name":"testName Companydfgdfgf"}
{"id":"10","companies_name":"testName Company"}
{"id":"13","companies_name":"testName Company"}

Использую Newtonsoft.Json, вот так:

Companies restoredCompanies = JsonConvert.DeserializeObject<Companies>(result.message);

Если JSON приходит с 1 объектом, все ок, если несколько то возникает ошибка:
«Additional text encountered after finished reading JSON content: {. Path », line 1, position 37.»

Я понимаю причину ошибки, то что я несколько элементов пытаюсь записать в 1 объект, но я пытался сделать и вот так:

List<Companies> restoredCompanies = JsonConvert.DeserializeObject<List<Companies>>(result.message);
// и так:

Companies[] restoredCompanies = JsonConvert.DeserializeObject<Companies[]>(result.message);

А вот класс Companies:

class Companies
    {
        public string id { get; set; }
        public string companies_name { get; set; }
    }

Но что то не получается.

Я понимаю что вопрос мега тупой и очень простой, не судите пожалуйста)

P.S. Спасибо всем огромное!

I’m trying to deserialize some JSON response. With simple response I’ve no problem but with a complex response I get this error:

Cannot deserialize the current JSON object (e.g. {«name»:»value»})
into type
‘System.Collections.Generic.List`1[APIEffilogics.Usuari+Node]’ because
the type requires a JSON array (e.g. [1,2,3]) to deserialize
correctly.

To fix this error either change the JSON to a JSON array (e.g.
[1,2,3]) or change the deserialized type so that it is a normal .NET
type (e.g. not a primitive type like integer, not a collection type
like an array or List) that can be deserialized from a JSON object.
JsonObjectAttribute can also be added to the type to force it to
deserialize from a JSON object.

It seems that I have a problem with the type of I put when deserialize the string. The JSON string is like this:

{

        nodes: [
          {
            id: 5,
            global_id: 5,
            description: "Oven",
            room_id: 2,
            floor_id: 1,
            building_id: 1,
            client_id: 2,
            nodemodel_id: 2,
            nodetype_id: 1
          },
          {
            id: 39,
            global_id: 39,
            description: "Fridge",
            room_id: 2,
            floor_id: 1,
            building_id: 1,
            client_id: 2,
            nodemodel_id: 8,
            nodetype_id: 1
          }, ...
        ],
        limit: 10,
        offset: 0
    }

And those are the classes:

public class Node : Usuari      //Estructura nodes
{            
   [JsonProperty("limit")]
   public int limit { get; set; }
   [JsonProperty("offset")]
   public int offset { get; set; }
   [JsonProperty("nodes")]
   public List<Node_sub> nodes_sub { get; set; }
}
public class Node_sub : Node
{
    [JsonProperty("id")]
    public string nid { get; set; }
    [JsonProperty("global_id")]
    public string gid { get; set; }
    [JsonProperty("description")]
    public string descrip { get; set; }
    [JsonProperty("room_id")]
    public string rid { get; set; }
    [JsonProperty("floor_id")]
    public string fid { get; set; }
    [JsonProperty("client_id")]
    public string cid { get; set; }
    [JsonProperty("building_id")]
    public string bid { get; set; }
    [JsonProperty("nodemodel_id")]
    public string model { get; set; }
    [JsonProperty("nodetype_id")]
    public string type { get; set; }
}

The code is:

public void Request(string url, string metode, string value)
        {
            try
            {
                //Enviem la petició a la URL especificada i configurem el tipus de connexió
                HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);

                myReq.KeepAlive = true;
                myReq.Headers.Set("Cache-Control", "no-store");
                myReq.Headers.Set("Pragma", "no-cache");
                myReq.Headers.Set("Authorization", usuari.token_type + " " + usuari.access_token);
                myReq.ContentType = "application/json";

                if (metode.Equals("GET") || metode.Equals("POST"))
                {
                    myReq.Method = metode;  // Set the Method property of the request to POST or GET.
                    if (body == true)
                    {
                        // add request body with chat search filters
                        List<paramet> p = new List<paramet>();
                        paramet p1 = new paramet();
                        p1.value = "1";
                        string jsonBody = JsonConvert.SerializeObject(value);
                        var requestBody = Encoding.UTF8.GetBytes(jsonBody);
                        myReq.ContentLength = requestBody.Length;
                        //myReq.ContentType = "application/json";
                        using (var stream = myReq.GetRequestStream())
                        {
                            stream.Write(requestBody, 0, requestBody.Length);   //Enviem el cos de la petició
                        }
                        body = false;
                    }
                }
                else throw new Exception("Invalid Method Type");

                //Obtenim la resposta del servidor
                HttpWebResponse myResponse = (HttpWebResponse)myReq.GetResponse();
                Stream rebut = myResponse.GetResponseStream();
                StreamReader readStream = new StreamReader(rebut, Encoding.UTF8); // Pipes the stream to a higher level stream reader with the required encoding format. 
                string info = readStream.ReadToEnd();

                if (tipus == 0) jsonclient = JsonConvert.DeserializeObject<List<Usuari.Client>>(info);
                else if (tipus == 1) jsonedif = JsonConvert.DeserializeObject<List<Usuari.Building>>(info);
                else if (tipus == 2) jsonplanta = JsonConvert.DeserializeObject<List<Usuari.Floor>>(info);
                else if (tipus == 3) jsonhab = JsonConvert.DeserializeObject<List<Usuari.Room>>(info);
                else if (tipus == 4) jsonnode = JsonConvert.DeserializeObject<List<Usuari.Node>>(info);
            }

            catch (WebException ex)
            {
                // same as normal response, get error response
                var errorResponse = (HttpWebResponse)ex.Response;
                string errorResponseJson;
                var statusCode = errorResponse.StatusCode;
                var errorIdFromHeader = errorResponse.GetResponseHeader("Error-Id");
                using (var responseStream = new StreamReader(errorResponse.GetResponseStream()))
                {
                    errorResponseJson = responseStream.ReadToEnd();
                }
                //var errorCode = JsonObject.Parse(errorResponseJson).Object("responseStatus")["errorCode"];
                //var errorMessage = JsonObject.Parse(errorResponseJson).Object("responseStatus")["message"];
            }
        }

Why I’m having this error? List<Usuari.Node> is an array that contains all the items of JSON message. I try to fix the error but I’m not able to find and answer. How can I fix it?

Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
[
    {
        "id": 7542826,
        "title": "Адрес 140",
        "address": "Адрес 140",
        "longitude": 05.961548,
        "latitude": 04.742206,
        "kkms": [
            {
                "id": 65231138,
                "orgId": 3122,
                "retailPlaceId": 7128126123,
                "internalName": "000423532061244",
                "model": "ZR2",
                "serialNumber": "0364589429",
                "onlineStatus": 1,
                "status": 4,
                "createdAt": 1580367599792,
                "declineReason": "",
                "fnsKkmId": "15975313354061244",
                "regStatus": "REGISTRATION_SUCCESS",
                "regStatusChangedAt": 165465370307890,
                "fiscalDrive": {
                    "producer": "",
                    "number": "54165453465469161",
                    "activationDate": 1580367540000
                },
                "lastShift": {
                    "kkmId": "5275257275061244",
                    "updateDate": 1752752752396335,
                    "shiftNumber": 187243,
                    "sells": 8895.61,
                    "returns": 0,
                    "lastTransaction": 1597252577410360000,
                    "shiftClosed": false,
                    "fiscalDriveReplaceRequired": false,
                    "fiscalDriveMemoryExceeded": false,
                    "fiscalDriveExhausted": false,
                    "fiscalDocumentsCount": 47,
                    "lastTransactionType": "TICKET"
                }
            },
            {
                "id": 657765130,
                "orgId": 3122,
                "retailPlaceId": 7128126123,
                "internalName": "000433185565000601",
                "model": "ZR2",
                "serialNumber": "08388284512361",
                "onlineStatus": 0,
                "status": 4,
                "createdAt": 1584534534534507,
                "declineReason": "",
                "fnsKkmId": "0004534534534530601",
                "regStatus": "REGISTRATION_SUCCESS",
                "regStatusChangedAt": 15453453453890,
                "fiscalDrive": {
                    "producer": "",
                    "number": "45354345354345566357",
                    "activationDate": 4534534534560000
                },
                "lastShift": {
                    "kkmId": "45354345345300601",
                    "updateDate": 1596094816137,
                    "shiftNumber": 1611,
                    "sells": 0,
                    "returns": 0,
                    "lastTransaction": 1597252577410360000,
                    "shiftClosed": false,
                    "fiscalDriveReplaceRequired": false,
                    "fiscalDriveMemoryExceeded": false,
                    "fiscalDriveExhausted": false,
                    "fiscalDocumentsCount": 0,
                    "lastTransactionType": "OPEN_SHIFT"
                }
            }
        ],
        "kkmsOnlineCount": 2
    }
]

I tried to fetch data from API but I receive an error:

{Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {«name»:»value»}) into type ‘System.Collections.Generic.List`1[pizhevsoft.Models.ItemsAPI+AladinModel]’ because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path ‘aladinModel’, line 1, position 15.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x003a0] in <7ca8898b690a4181a32a9cf767cedb1e>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in <7ca8898b690a4181a32a9cf767cedb1e>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <7ca8898b690a4181a32a9cf767cedb1e>:0
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00054] in <7ca8898b690a4181a32a9cf767cedb1e>:0
at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <7ca8898b690a4181a32a9cf767cedb1e>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <7ca8898b690a4181a32a9cf767cedb1e>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <7ca8898b690a4181a32a9cf767cedb1e>:0
at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in <7ca8898b690a4181a32a9cf767cedb1e>:0
at pizhevsoft.Services.RestServiceAPI.GetAladinData (System.String query) [0x00151] in C:\Users\Admin\Desktop\pizhevsoft\pizhevsoft\pizhevsoft\pizhevsoft\Services\RestServiceAPI.cs:30 }

My object class looks like:

public partial class RootAladinModel
{
    [JsonProperty("aladinModel")]
    public AladinModel[] AladinModel { get; set; }
}

public partial class AladinModel
{
    [JsonProperty("DATS")]
    public DateTimeOffset Dats { get; set; }

    [JsonProperty("TA")]
    public double Ta { get; set; }

    [JsonProperty("RH")]
    public double Rh { get; set; }

    [JsonProperty("WS")]
    public double Ws { get; set; }

    [JsonProperty("RR")]
    public double Rr { get; set; }

    [JsonProperty("SR")]
    public double Sr { get; set; }

    [JsonProperty("APRES")]
    public double Apres { get; set; }
}

My Rest Service Class look like:

public async Task<List<AladinModel>> GetAladinData(string query)
{
    List<AladinModel> weatherData = new List<AladinModel>();
    try
    {
        var response = await _client.GetAsync(query);
        if (response.IsSuccessStatusCode)
        {
            var content = await response.Content.ReadAsStringAsync();
            weatherData = JsonConvert.DeserializeObject<List<AladinModel>>(content);
        }
    }
    catch (Exception ex)
    {
        Debug.WriteLine("\t\tERROR {0}", ex.Message);
    }

    return weatherData;
}

I receive this error in the catch statement.

This is the JSON data:

{"aladinModel":[[{"DATS":"2022-03-16T00:00:00.000Z","TA":1,"RH":56.9,"WS":1.5,"RR":0,"SR":0,"APRES":97772.6},{"DATS":"2022-03-16T03:00:00.000Z","TA":0.7,"RH":58.6,"WS":1,"RR":0,"SR":0,"APRES":97581.8},{"DATS":"2022-03-16T06:00:00.000Z","TA":2.7,"RH":66.1,"WS":1.7,"RR":0,"SR":0,"APRES":97512.6},{"DATS":"2022-03-16T09:00:00.000Z","TA":7.4,"RH":71.5,"WS":2.4,"RR":0,"SR":0,"APRES":97237.5},{"DATS":"2022-03-16T12:00:00.000Z","TA":8.4,"RH":76,"WS":1.7,"RR":0,"SR":0,"APRES":97146},{"DATS":"2022-03-16T15:00:00.000Z","TA":7.1,"RH":85.8,"WS":1.5,"RR":0.1,"SR":0,"APRES":97032.2},{"DATS":"2022-03-16T18:00:00.000Z","TA":3.9,"RH":91.9,"WS":0.7,"RR":0,"SR":0,"APRES":97047.9},{"DATS":"2022-03-16T21:00:00.000Z","TA":4.2,"RH":86.7,"WS":2.1,"RR":0,"SR":0,"APRES":97117.8},{"DATS":"2022-03-17T00:00:00.000Z","TA":4.9,"RH":90.5,"WS":3.1,"RR":0.3,"SR":0,"APRES":97175.7},{"DATS":"2022-03-17T03:00:00.000Z","TA":4.4,"RH":94.3,"WS":1.6,"RR":0.9,"SR":0,"APRES":97240.9},{"DATS":"2022-03-17T06:00:00.000Z","TA":2.8,"RH":92.9,"WS":1,"RR":1.6,"SR":0,"APRES":97632.1},{"DATS":"2022-03-17T09:00:00.000Z","TA":6.2,"RH":65.1,"WS":3.6,"RR":0,"SR":0,"APRES":97670.4},{"DATS":"2022-03-17T12:00:00.000Z","TA":7.1,"RH":64,"WS":3.9,"RR":0,"SR":0,"APRES":97684.8},{"DATS":"2022-03-17T15:00:00.000Z","TA":5.2,"RH":82,"WS":4.5,"RR":0.1,"SR":0,"APRES":97723.2},{"DATS":"2022-03-17T18:00:00.000Z","TA":1.8,"RH":82,"WS":3.3,"RR":0,"SR":0,"APRES":97906.4},{"DATS":"2022-03-17T21:00:00.000Z","TA":0.7,"RH":82.6,"WS":2.6,"RR":0.1,"SR":0,"APRES":98167.4},{"DATS":"2022-03-18T00:00:00.000Z","TA":-0.3,"RH":79.7,"WS":1.6,"RR":0.2,"SR":0.1,"APRES":98345.8},{"DATS":"2022-03-18T03:00:00.000Z","TA":-1.2,"RH":87,"WS":1.8,"RR":0.2,"SR":0.1,"APRES":98387.1},{"DATS":"2022-03-18T06:00:00.000Z","TA":-2,"RH":66.6,"WS":2,"RR":0,"SR":0,"APRES":98589.5},{"DATS":"2022-03-18T09:00:00.000Z","TA":2.1,"RH":43.4,"WS":4.4,"RR":0,"SR":0,"APRES":98570.8},{"DATS":"2022-03-18T12:00:00.000Z","TA":4.2,"RH":37.7,"WS":4,"RR":0,"SR":0,"APRES":98496.9},{"DATS":"2022-03-18T15:00:00.000Z","TA":3.1,"RH":38.2,"WS":3.3,"RR":0,"SR":0,"APRES":98481.8},{"DATS":"2022-03-18T18:00:00.000Z","TA":-0.5,"RH":49.8,"WS":2.8,"RR":0,"SR":0,"APRES":98632.9},{"DATS":"2022-03-18T21:00:00.000Z","TA":-1.6,"RH":46.4,"WS":2.6,"RR":0,"SR":0,"APRES":98658.8},{"DATS":"2022-03-19T00:00:00.000Z","TA":-2.2,"RH":53.2,"WS":1.7,"RR":0,"SR":0,"APRES":98663},{"DATS":"2022-03-19T03:00:00.000Z","TA":-3.4,"RH":64.3,"WS":0.5,"RR":0,"SR":0,"APRES":98617.2},{"DATS":"2022-03-19T06:00:00.000Z","TA":-2.4,"RH":64,"WS":1.5,"RR":0,"SR":0,"APRES":98723.9},{"DATS":"2022-03-19T09:00:00.000Z","TA":1.7,"RH":50.1,"WS":3.3,"RR":0,"SR":0,"APRES":98627.5},{"DATS":"2022-03-19T12:00:00.000Z","TA":3,"RH":45.2,"WS":3.2,"RR":0,"SR":0,"APRES":98513.8},{"DATS":"2022-03-19T15:00:00.000Z","TA":1.7,"RH":53,"WS":3.2,"RR":0.1,"SR":0,"APRES":98504.2},{"DATS":"2022-03-19T18:00:00.000Z","TA":-0.9,"RH":50.1,"WS":3,"RR":0,"SR":0,"APRES":98630},{"DATS":"2022-03-19T21:00:00.000Z","TA":-2.8,"RH":54.3,"WS":1.6,"RR":0,"SR":0,"APRES":98747.2},{"DATS":"2022-03-20T00:00:00.000Z","TA":-3.5,"RH":54.1,"WS":1.5,"RR":0,"SR":0,"APRES":98752.8},{"DATS":"2022-03-20T03:00:00.000Z","TA":-4.5,"RH":59.8,"WS":1.4,"RR":0,"SR":0,"APRES":98672.5},{"DATS":"2022-03-20T06:00:00.000Z","TA":-2.6,"RH":57.7,"WS":1.9,"RR":0,"SR":0,"APRES":98805.5},{"DATS":"2022-03-20T09:00:00.000Z","TA":2.1,"RH":40.3,"WS":2.1,"RR":0,"SR":0,"APRES":98701.4},{"DATS":"2022-03-20T12:00:00.000Z","TA":4.4,"RH":37.6,"WS":1.9,"RR":0,"SR":0,"APRES":98568},{"DATS":"2022-03-20T15:00:00.000Z","TA":3.9,"RH":40.3,"WS":1,"RR":0,"SR":0,"APRES":98467.1},{"DATS":"2022-03-20T18:00:00.000Z","TA":0.2,"RH":50.9,"WS":4.3,"RR":0,"SR":0,"APRES":98518.3},{"DATS":"2022-03-20T21:00:00.000Z","TA":-0.3,"RH":47.7,"WS":2.6,"RR":0,"SR":0,"APRES":98505.9},{"DATS":"2022-03-21T00:00:00.000Z","TA":-2.3,"RH":53.8,"WS":1.6,"RR":0,"SR":0,"APRES":98413.8},{"DATS":"2022-03-21T03:00:00.000Z","TA":-2.4,"RH":54.6,"WS":1.7,"RR":0,"SR":0,"APRES":98278.5},{"DATS":"2022-03-21T06:00:00.000Z","TA":-0.8,"RH":51.8,"WS":1.2,"RR":0,"SR":0,"APRES":98361.4},{"DATS":"2022-03-21T09:00:00.000Z","TA":4.5,"RH":38.3,"WS":2.1,"RR":0,"SR":0,"APRES":98296.6},{"DATS":"2022-03-21T12:00:00.000Z","TA":5.9,"RH":40.8,"WS":2,"RR":0,"SR":0,"APRES":98131.2},{"DATS":"2022-03-21T15:00:00.000Z","TA":5.8,"RH":45.8,"WS":2.1,"RR":0,"SR":0,"APRES":98015.5},{"DATS":"2022-03-21T18:00:00.000Z","TA":1.4,"RH":52.7,"WS":3.8,"RR":0,"SR":0,"APRES":98064.1},{"DATS":"2022-03-21T21:00:00.000Z","TA":0.2,"RH":53.3,"WS":1.9,"RR":0,"SR":0,"APRES":98108.2},{"DATS":"2022-03-22T00:00:00.000Z","TA":-0.8,"RH":60,"WS":3,"RR":0,"SR":0,"APRES":98065},{"DATS":"2022-03-22T03:00:00.000Z","TA":0.5,"RH":52.9,"WS":3,"RR":0,"SR":0,"APRES":97926.2},{"DATS":"2022-03-22T06:00:00.000Z","TA":3.7,"RH":50.3,"WS":4.4,"RR":0,"SR":0,"APRES":97894.1},{"DATS":"2022-03-22T09:00:00.000Z","TA":8.2,"RH":50.8,"WS":3.4,"RR":0,"SR":0,"APRES":97786},{"DATS":"2022-03-22T12:00:00.000Z","TA":11,"RH":51.4,"WS":3,"RR":0,"SR":0,"APRES":97563.2},{"DATS":"2022-03-22T15:00:00.000Z","TA":9,"RH":57.7,"WS":5,"RR":0.5,"SR":0,"APRES":97473.7},{"DATS":"2022-03-22T18:00:00.000Z","TA":5.7,"RH":57.6,"WS":2.9,"RR":0,"SR":0,"APRES":97661.6},{"DATS":"2022-03-22T21:00:00.000Z","TA":2.6,"RH":63.9,"WS":2.5,"RR":0,"SR":0,"APRES":97793.2},{"DATS":"2022-03-23T00:00:00.000Z","TA":0.5,"RH":74.8,"WS":1.3,"RR":0,"SR":0,"APRES":97811.7},{"DATS":"2022-03-23T03:00:00.000Z","TA":0.2,"RH":69.7,"WS":2.1,"RR":0,"SR":0,"APRES":97797.9},{"DATS":"2022-03-23T06:00:00.000Z","TA":2.2,"RH":69.5,"WS":1.1,"RR":0,"SR":0,"APRES":97815.5},{"DATS":"2022-03-23T09:00:00.000Z","TA":6.9,"RH":49.9,"WS":2.2,"RR":0,"SR":0,"APRES":97818.5},{"DATS":"2022-03-23T12:00:00.000Z","TA":9,"RH":43.6,"WS":1.4,"RR":0,"SR":0,"APRES":97653.9},{"DATS":"2022-03-23T15:00:00.000Z","TA":9,"RH":47.1,"WS":1.1,"RR":0,"SR":0,"APRES":97537.8},{"DATS":"2022-03-23T18:00:00.000Z","TA":3.2,"RH":60.4,"WS":1.2,"RR":0,"SR":0,"APRES":97628.5},{"DATS":"2022-03-23T21:00:00.000Z","TA":3.2,"RH":61.6,"WS":3.3,"RR":0,"SR":0,"APRES":97612.5},{"DATS":"2022-03-24T00:00:00.000Z","TA":3.9,"RH":59.4,"WS":3.6,"RR":0,"SR":0,"APRES":97508.8},{"DATS":"2022-03-24T03:00:00.000Z","TA":4.7,"RH":57.9,"WS":4.1,"RR":0,"SR":0,"APRES":97392.8},{"DATS":"2022-03-24T06:00:00.000Z","TA":7,"RH":58.3,"WS":3.8,"RR":0,"SR":0,"APRES":97404.7},{"DATS":"2022-03-24T09:00:00.000Z","TA":12,"RH":50.9,"WS":3.4,"RR":0,"SR":0,"APRES":97354.4},{"DATS":"2022-03-24T12:00:00.000Z","TA":14.5,"RH":42.2,"WS":3.5,"RR":0,"SR":0,"APRES":97181.6},{"DATS":"2022-03-24T15:00:00.000Z","TA":14.2,"RH":45.7,"WS":3.4,"RR":0,"SR":0,"APRES":97068.2},{"DATS":"2022-03-24T18:00:00.000Z","TA":8.4,"RH":56.2,"WS":2.1,"RR":0,"SR":0,"APRES":97086.9},{"DATS":"2022-03-24T21:00:00.000Z","TA":7.7,"RH":52.9,"WS":3.5,"RR":0,"SR":0,"APRES":97200.7}],{"fieldCount":0,"affectedRows":504,"insertId":0,"serverStatus":34,"warningCount":0,"message":"","protocol41":true,"changedRows":0}]}

How can I fix this error?

>Solution :

A very strange yet valid JSON.

JSON Formatter & Validator

enter image description here

You need to get the first item (array) from aladinModel array.

using Newtonsoft.Json.Linq;

var content = await response.Content.ReadAsStringAsync();

JObject root = JObject.Parse(content);
weatherData = root["aladinModel"][0].ToObject<List<AladinModel>>();

Sample program

Понравилась статья? Поделить с друзьями:
  • Ошибка при делении на ноль java
  • Ошибка при добавлении принтера 0x000004f1
  • Ошибка при декодировании содержимого
  • Ошибка при декодировании заполнения oaep windows admin center
  • Ошибка при вычислении функции знач