how to know the return type of json object using LogFile in c#

Posted by Kasani007 under C# on 4/6/2018 | Points: 10 | Views : 654 | Status : [Member] | Replies : 2
How to know the return type of json object using LogFile in c#




Responses

Posted by: Sheonarayan on: 4/8/2018 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Return type of json object is always string. The other workaround is to have a property in the object and set it before json serialization so that in the json string you know what was the type.



Regards,
Sheo Narayan
http://www.dotnetfunda.com

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vedikaledange on: 1/7/2019 [Member] Starter | Points: 25

Up
0
Down
public class LazyJsonizer<T>
{
T Value;

public LazyJsonizer(T value)
{
Value = value;
}

override public string ToString()
{
return LazyJsonizer.Instance.Format(null, Value, null);
}
}

public class LazyJsonizer : IFormatProvider, ICustomFormatter
{
static public readonly LazyJsonizer Instance = new LazyJsonizer();

static public LazyJsonizer<T> Create<T>(T value)
{
return new LazyJsonizer<T>(value);
}

public object GetFormat(Type formatType)
{
return this;
}

public string Format(string format, object arg, IFormatProvider formatProvider)
{
try
{
return JsonConvert.SerializeObject(arg);
}
catch (Exception ex)
{
return ex.Message;
}
}
}

DOT NET

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response