Hi,
I'm trying to import an object that contains a TimeSpan field (as string).
I already created a TimeSpanImporter class with the function ImportFromString...
The function is called correctly and the TimeSpan is created fine, but after that I get an exception {"Found String where Member was expected."}.
Here is the object:
public class ETest {
public TimeSpan tm { get; set; }
}
The string sent:
"{\"tm\":\"11:28:47\"}"
The overrided function:
protected override object ImportFromString(ImportContext context, JsonReader reader){
try {
TimeSpan tm;
bool ok=TimeSpan.TryParse(reader.Text, out tm);
if (!ok) tm=(TimeSpan) base.ImportFromString(context, reader);
return tm;
} catch (Exception ex) {
SLogger.Error(this, ex.ToString());
}
return null;
}
The function that calls the import:
static public testImport(string txt){
try{
JsonConvert.Import(parameter.ParameterType, txt);// txt="{\"tm\":\"11:28:47\"}"
}catch(Exception ex){
//THIS EXCEPTION IS FIRED WITH MESSAGE: {"Found String where Member was expected."}.
}
}
What am I missing?
Thank you,
Bruno.