.net 4.0 - VB.Net Serialize anonymous type to xml -
in mvc can following serialise object anonymous type json...
public function getstatelist() jsonresult dim myobject = new {.id = 1, .property = "somevalue"} return me.json(myobject) end function
which return like;
{ "id": 1, "property"somevalue", }
i'd same output xml. haven't been able find equivalent method. please point me in right direction?
many thanks
the short answer cannot, see post. recommend create concrete type represent structure of anonymous output, , use normal xml serialization technique example i've provided below.
here basic example of how use (sorry it's in c# syntax):
using (memorystream memstream = new memorystream()) { system.text.utf8encoding utf8 = new system.text.utf8encoding(); // read , convert byte array xmlserializer serializer = new xmlserializer( <<yourobject>>.gettype() ); serializer.serialize( memstream, <<yourobject>>)); string output = utf8.getstring( memstream.toarray() ); }
Comments
Post a Comment