Home > Software design >  Deserialization malformed JSON with custom constructor
Deserialization malformed JSON with custom constructor

Time:05-29

Is there any way to deserialize this malformed JSON code?

{
"children": [
{
  "bold": false,
  "italic": false,
  "strike": false,
  "underline": false,
  "link": false
},
"Hello world" ]
}

JsonSerializerOptions has the option of a custom Converters.

Would anyone know how to show me the way?

Thank you.

CodePudding user response:

the simpliest way to deserialize your json is

var data = JsonConvert.DeserializeObject<Data>(json);

public class Data
{
    public List<object> children { get; set; }
}

how to use

string helloWorld=data.children[1].ToString();

Dictionary<string,bool> fonts= ((JObject) data.children[0]).ToObject<Dictionary<string,bool>>();
  • Related