How to create an array in a JSON query with C#

Hello all,

This request is refering to an existing request, which works great, but i have one small addition. In the above solution, there is only one option, but now i have more like:
"options": [
{
"key": "DOOR"
},
{
"key": "REFERENCE",
"input": "TEST JEROEN"
}
],

Open in new window


In the above solution one option is made with the following code:
     options = new[] { new { key = "DOOR" } },
                   

Open in new window


My question is, how can i make the orther(s). When i try this i get an error that my array is not correct. I tried something like:
   options = new object[] { 
                            new { key = "DOOR" }, 
                            new { key = "REFERENCE"}, 
                            new {input = dhlLabelRequest.orderReference.ToString() }

Open in new window


But this didn't work.

Thanks in advance.

Edward
Edward van NijmweegenICT employeeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
Your C# object array does not match the expected JSON results -
"options": [
    {
        "key": "DOOR"
    },{
        "key": "REFERENCE",
        "input": "TEST JEROEN"
    }
]

Open in new window

To make the array match the JSON result you would need to do something like -
options = new object[] { new { key = "DOOR" }, new { key = "REFERENCE", input = dhlLabelRequest.orderReference } }

Open in new window

That being said, I don't think that the dhl route allows for this option type.  Looking at the API reference states:Capture.PNG
-saige-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Edward van NijmweegenICT employeeAuthor Commented:
Hello Saige,

Again thank you a lot. It is working as it should work.

Even with your comment at the end it does do the job.

Thanks,

Edward
it_saigeDeveloperCommented:
Glad it worked out for you.

-saige-
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.