0

I'm looking to construct a C# object to produce the following JSON array:

["Key":"SomeKeyValue", "Key":"SomeKeyValue"]

Using a list gives me the array I'm after, but with a object name in the resulting JSON:

Public Class SomeOtherClass
{
    public string Key {get; set;}
}

Public Class SomeObject
{
    public List<SomeOtherClass> PropertyName { get; set; }
}

// JSON
{"PropertyName":[ {"Key":"SomeValue"} ] }

I need to drop the name of the object in the resulting JSON. Using a Dictionary<string,string> gives me what I'm after but with the Object syntax {} in the JSON instead if the Array []:

{
  ...
}

Trying to avoid custom serializer and contracts here if possible. I'm sure that NewtonSoft must have some magic attribute here?

Found a few related questions on the net, but none that resolves removing the property name. Any suggestions?

buddemat
  • 4,552
  • 14
  • 29
  • 49

1 Answers1

0

From looking at a XML to JSON converter, the conversion from the XML:

<ClassName>
    <!--Zero or more repetitions:-->
    <key>value1</key>
    <key>value2</key>
    <key>value3</key>
</ClassName>

has the JSON equivalent of:

"ClassName": {
    "key": [
        "value1",
        "value2",
        "value3"
    ]
}

Using this for now until I can test it on more 3rd party systems that I need to integrate with.