serialization - Converting to correctly formatted JSON -


i've been tasked calling api, needs take json payload request.. example format of json follows:

{      "method":"methodname",    "in":[         {            "account":"acme",          "context":"abc123"       },       "content",       {            "msearchtext":"chocolate",          "mitemdataids":[               "entry:id",             "entry:entryref",             "entry:categoryid"          ]       }    ] } 

i using json.net (newstonsoft) construct json .net objects. issue facing correctly constructing "in" section.. appears array of objects, second item has title ("content",{.....})..

the closest can is:

{   "method": "methodname",   "in":[     {       "account": "pando",       "context": "sdfsd22342"     },     {       "msearchtext":"chocolate",       "mitemdataids":[         "entry:id",         "entry:entryref",         "entry:categoryid"       ]     }   ] } 

which identical apart "content", missing:

my code far is:

public class payload     {         public string method { get; set; }         [jsonproperty("in")]         public list<object> items { get; set; }     }      public class accountdetails     {         public string account { get; set; }         public string context { get; set; }     }      [jsonobject(title = "content")]     public class content     {         public string msearchtext { get; set; }         public string[] mitemdataids { get; set; }     }          payload payload = new payload();         payload.method = "methodname";         payload.items = new list<object>();         payload.items.add(new accountdetails         {             account = "acme",             context = "abc123"         });         content conent = new content         {             msearchtext = "chocolate",             mitemdataids = new string[] { "entry:id", "entry:entryref", "entry:categoryid" }         };         payload.items.add(conent);          string jsonobject = jsonconvert.serializeobject(payload, formatting.indented); 

any suggestions on can do?


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -