c# - Issues generating array in object for Json -
i trying fill following object the data list object.
public class documentqueryobject { public document[] documents { get; set; } } public class document { public documentobj document { get; set; } } public class documentobj { public string homecommunityid { get; set; } public string repositoryid { get; set; } public string documentuuid { get; set; } public string doctype { get; set; } }
i need able build following json
{ "documents": { "document": [ { "doctype": "", "homecommunityid": "2.16.470.1.100.1.1.1000.990.1", "repositoryid": "2.16.470.1.100.1.1.1000.990.1", "documentuuid": "91092" } ] } }
so using following c# code
documentqueryobject documents = new documentqueryobject() { documents = new[] { new document() { document = new [] { obj.select(s => new documentobj() { doctype = s.doctype }) } } } };
the obj list of documentquery objects below
public class documentquery { public string doctype { get; set; } public string homecommunityid { get; set; } public string repositoryid { get; set; } public string documentuuid { get; set; } }
so need assign these multiple documentquery objects list documentqueryobject.
can help?
your document
class has property a documentobj
trying create array of documentobj
you should doing this:
documentqueryobject documents = new documentqueryobject() { documents = new[] { new document() { document = new documentobj() } } };
though have not posted obj
, trying achieve. though above may rid of error may need add more context problem more thorough answer.
update
if want document collection can change classes suggested @dbc in comments:
public class document { public list<documentobj> document { get; set; } } documentqueryobject documents = new documentqueryobject() { documents = new[] { new document() { document = obj.select(s => new documentobj() { doctype = s.doctype }).tolist() } } };
Comments
Post a Comment