Error in Deserialize C#

Asked

Viewed 42 times

1

By taking the information from my Json and trying to deserialize, the same error or displays 0, I have tried N methods, does anyone give me a light? I thank you from the outset, follow the code.

//example

{
"pulse": {
"url": "https://amdm.monday.com/projects/360886706",
"id": 360886706,
"name": "PO0008 -> Suporte Embraer",
"updates_count": 0,
"board_id": 251379198,
"created_at": "2019-10-28T20:04:36Z",
"updated_at": "2019-10-29T22:23:30Z"
},
"board_meta": {
"position": 65408,
"group_id": "new_group32"
},
"column_values": [
{
"cid": "name",
"title": "Name",
"name": "PO0008 -> Suporte Embraer"
},
{
"cid": "person90",
"title": "Pessoa",
"value": null
},
{
"cid": "date741",
"title": "Data",
"value": null
},
{
"cid": "status8",
"title": "Desenho",
"value": null
},
{
"cid": "person9",
"title": "Pessoa",
"value": null
},
{
"cid": "text7",
"title": "Nun SC/PC",
"value": null
},
{
"cid": "date03",
"title": "Data",
"value": null
},
{
"cid": "status14",
"title": "Compra Material",
"value": null
},
{
"cid": "people7",
"title": "People",
"value": null
},
{
"cid": "text73",
"title": "Qtd",
"value": null
},
{
"cid": "file",
"title": "File",
"value": null
},
{
"cid": "date8",
"title": "Data",
"value": null
},
{
"cid": "status5",
"title": "Produção",
"value": null
},
{
"cid": "n_meros",
"title": "HU-Naldo",
"value": null
},
{
"cid": "numbers0",
"title": "HU-Adão",
"value": null
},
{
"cid": "item_id",
"title": "Item ID",
"value": null
}
]
}
]

//----------------------- //class

namespace AT_monday
{


    public class RootObject
    {
        [JsonProperty("pulse")]
        public Pulse[] pulse { get; set; }
        [JsonProperty("board_meta")]
        public BoardMeta[] board_meta { get; set; }
        [JsonProperty("column_values")]
        public List<ColumnValue>[] column_values { get; set; }
    }

    public class Pulse
    {
        [JsonProperty("url")]
        public string url { get; set; }
        [JsonProperty("id")]
        public string id { get; set; }
        [JsonProperty("name")]
        public string name { get; set; }
        [JsonProperty("updates_count")]
        public int updates_count { get; set; }
        [JsonProperty("board_id")]
        public int board_id { get; set; }
        [JsonProperty("created_at")]
        public DateTime created_at { get; set; }
        [JsonProperty("updated_at")]
        public DateTime updated_at { get; set; }
    }

    public class BoardMeta
    {
        [JsonProperty("position")]
        public string position { get; set; }
        [JsonProperty("group_id")]
        public string group_id { get; set; }
    }

    public class ColumnValue
    {
        [JsonProperty("cid")]
        public string cid { get; set; }
        [JsonProperty("title")]
        public string title { get; set; }
        [JsonProperty("name")]
        public string name { get; set; }
        [JsonProperty("value")]
        public object value { get; set; }

    }
}

//-------------

//code

var requisicaoWeb = WebRequest.CreateHttp(@"Url");
requisicaoWeb.Method = "GET";
requisicaoWeb.UserAgent = "RequisicaoWebDemo";
var resposta = requisicaoWeb.GetResponse();
var streamDados = resposta.GetResponseStream();
StreamReader reader = new StreamReader(streamDados);
string objResponse = reader.ReadToEnd();

var pedidosApi = JsonConvert.DeserializeObject<RootObject>(objResponse);
txt1.Text = Convert.ToString(pedidosApi);
  • Good morning, your Json has an error, there are several online formatters that help you format your Json making it easy for you to find possible errors in the code. It may not be just that, but it’s worth it just to tidy up. I used: https://jsonformatter.org Moacir.

  • The error @Moacir refers to is an extra square bracket ("]") at the end of JSON.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.