vb.net - Trying to convert an entire structure to a string in ASP.NET -
i'm using structure follows:
structure userrec public userrecid integer public companyrecid integer public username string public loggedintime datetime public userislocked boolean public userfirstname string public userlastname string public useremail string ... deleted simplicity ... end structure
when instantiate type variable (dim thisuserrec userrec = (data routine) )
, can break code , go immediate window , type "? thisuserrec"
, see nice display of every element in structure
? thisuserrec {userrec} userfirstname: "alex " userisdeleted: false userislocked: false userisownermgr: false
i removed elements security , simplicity purposes in example.
so, i'd love save entire structure audit table string. hoping there easy way
dim thisuserrecstring string = thisuserrec
but of course, know won't work.
anybody know quick way dump contents of structure string? or html table?
you can easely serialize json datacontractjsonserializer.
this guy has great example: how can make datacontractjsonserializer serialize object string?
i converted vb
private function tojson(of t)(data t) string dim serializer new datacontractjsonserializer(gettype(t)) using ms new memorystream() serializer.writeobject(ms, data) return encoding.[default].getstring(ms.toarray()) end using end function
just call this
tojson(of userrec)(object)
don't forget import libraries
imports system.runtime.serialization.json imports system.io imports system.text
and make serializable
<serializable()> _
Comments
Post a Comment