mercredi 21 décembre 2016

Convert object content to json string

I'm using reflection to deserialize object from binary stream ("objType=SM.Backend.Entities.Erp.CodeListBase"):

var methodInfo = typeof(SM.Core.Serializator).GetMethod("DeserializeCache");
var genericMethod = methodInfo.MakeGenericMethod(objType);
var _objItem = genericMethod.Invoke(null, new[] { _streamedData });

It works. If I inspect _objItem in Locals window it looks like:_objItem

Now i would like to export _objItem content to json string:

var jsonString=JsonConvert.SerializeObject(_objItem, Formatting.Indented);

But result is empty: "[]". If I do the same for other objects it works. I guess for this object it doesn't work because it is complex type(nested):

SM.Backend.Entities.Erp.CodeListBase{SM.Backend.Entities.Erp.CodeList<SM.Backend.Entities.Erp.MaterialType>}.

Any idea how to extract the content from locals to json string? Should I convert object to different type first?





Aucun commentaire:

Enregistrer un commentaire