I have the following JSON that I need to post to an API:
{
"arch": {
"id": “TrackingCode”
},
"nails": [{
"name": "John"
}],
"token": 'RandomCode'
}
So I define the data this way:
public class arch
{
[JsonProperty("id")]
public string id { get; set; }
}
public class nails
{
[JsonProperty("name")]
public string[] name { get; set; }
}
public class Parameter
{
[JsonProperty("arch")]
public arch arch { get; set; }
[JsonProperty("nails")]
public nails nails{ get; set; }
[JsonProperty("token")]
public string token { get; set; }
}
This is how I init the JSON before serializing it:
Parameter json = new Parameter
{
arch = new arch
{
id = TrackingId
},
nails = new nails
{
name = "John"
}
token = "randomstuff"
};
But there is a syntax/formatting error involving the "name" field that won't allow compilation. It's obviously the array structure of that element. What am I doing wrong syntax wise?