How to remove curly brackets using C#.?

My Array {[{ "SKU":"53823","OrderNo":"12345678563423"}]} I want to get OrderNo How.?

1 answer

  • answered 2021-02-20 12:00 Sam

    The first and last curly brackets are preventing you to deserialize the string. How do you get this json string? A quick fix could be something like this:

    var json = "{[{ 'SKU':'53823','OrderNo':'12345678563423'}]}";       
    var jsonFix = json.TrimEnd('}').TrimStart('{');
    
    var obj = JsonConvert.DeserializeObject<List<Item>>(jsonFix);
    
    class Item
    {
        [JsonProperty("SKU")]
        public int SKU { get; set; }
        [JsonProperty("OrderNo")]
        public string OrderNo { get; set; }
    }
    

    But note that this isn't the right way to do it. You should change your json serialization!