c# - json array is not created properly for my scenario in json.net? -
i want create 1 json string using json.net in c#.but json array not created expected.here code... please help me out of issue...
markinfo[] markupdate1=new markinfo[2]; string jsonstring = jsonconvert.serializeobject(new { markupdate =markupdate1 }, formatting.indented); homecoming jsonstring; public class markinfo { list<string> finalmarks = new list<string>(); list<string> evalmarks = new list<string>(); } my expected output :
{ "markupdate":[ { "finalmarks":[ { } ] }, { "evalmarks":[ { } ] } ] } but generated next output :
{ "markupdate": [ null, null ] }
you're creating anonymous type has markupdate property assigned value of array contains no object instances.
are trying output 1 instance of markupdate? in case remove array, instantiate markinfo class , serialize that.
you should create finalmarks , evalmarks properties, not marked public.
string jsonstring = jsonconvert.serializeobject(new markinfo(), formatting.indented); homecoming jsonstring; public class markinfo { private list<string> finalmarks; private list<string> evalmarks; public list<string> finalmarks { { homecoming this.finalmarks ?? (this.finalmarks = new list<string>()); } set { this.finalmarks = value; } } public list<string> evalmarks { { homecoming this.evalmarks ?? (this.evalmarks = new list<string>()); } set { this.evalmarks = value; } } } c# asp.net json json.net
No comments:
Post a Comment