I have the following two classes.
public class Foo
{
public Bar Args { get; set; }
public Foo()
{
Args = new Bar();
}
}
public class Bar
{
public string Name { get; set; }
public int Age { get; set; }
}
When using:
var foo = new Foo();
foo.Args.Name = "Mikael";
foo.Args.Age = 12;
string o = JsonConvert.SerializeObject(foo);
Console.WriteLine(o);
I get the following json:
{"Args":{"Name":"Mikael","Age":12}}
This is somewhat correct i guess … but the other end I’m sending it to expects the Args to be an array, so it needs to look like this:
{"Args":[{"Name":"Mikael","Age":12}]}
Otherwise it sees the Args as a single object and not an array.
Can this be done with json.net ?
1 Answer