c# - Nested Json array in MVC Controller -


pretty silly question ask. not figure out .

in c# mvc controller action , need model json array testing purposes.

but shows me compilation errors instead of being valid json:

var result = {     "controllerid": "controller1",     "controllername": "controllerone" }; 

but valid :

var scheduleresult = new[]  {    new { scheduleid = "schedule1",schedulename = "scheduleone"},    new { scheduleid = "schedule2",schedulename = "scheduletwo"} }; 

why ?

also how write nested json array :

i tried :

var scheduleresult = new[]  {     new { scheduleid = "schedule1",schedulename = "scheduleone",new[]{ new {doorid="door1",doorname="doorone"}, new { doorid = "door2", doorname = "doortwo" } } },     new { scheduleid = "schedule2",schedulename = "scheduletwo"} }; 

but shows errors in syntax. ?

i need have nested array within each element of array .

thanks in advance.

well, c# not support way wrote. can't type in json in c# , expect work unfortunately. can try anonymous type:

 var result = new   {      controllerid = "controller1",      controllername = "controllerone",      myarray = new []       {           "a",           "b"      }  }; 

this converted json no problem if return result of api call.

the nested arrays talking don't work because need give them name, can't have array property without name. see example above.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -