Creating a JSON array in C#

前端 未结 4 1949
北恋
北恋 2021-01-30 02:04

Ok, so I am trying to send POST commands over an http connection, and using JSON formatting to do so. I am writing the program to do this in C#, and was wondering how I would f

4条回答
  •  悲&欢浪女
    2021-01-30 02:36

    You're close. This should do the trick:

    new {items = new [] {
        new {name = "command" , index = "X", optional = "0"}, 
        new {name = "command" , index = "X", optional = "0"}
    }}
    

    If your source was an enumerable of some sort, you might want to do this:

    new {items = source.Select(item => new 
    {
        name = item.Name, index = item.Index, options = item.Optional
    })};
    

提交回复
热议问题