4
嘗試反序列化無效的JSON時,是否有可能使ServiceStack.Text庫丟失?默認情況下,它看起來就像忽略了無效的JSON,以便結果對象包含空值。配置ServiceStack.Text以拋出無效的JSON
當我嘗試反序列化JSON這個(a「被MongoConnectionString後失蹤)
{
"MongoDb": {
"MongoConnectionString:"mongodb://localhost:27017/x",
"MongoDatabase":"x",
"MongoSafeModeEnabled":true,
"MongoSafeModeFSync":true,
"MongoSafeModeWriteReplicationCount":
"MongoSafeModeWriteTimeout":"00:00:00"
},
通過這樣做:JsonSerializer.DeserializeFromString(JSON); 其中
public class Configuration {
public class MongoDbSettings
{
public string MongoConnectionString {get;set;}
public string MongoDatabase {get;set;}
public bool MongoSafeModeEnabled {get;set;}
public bool MongoSafeModeFSync {get;set;}
public int MongoSafeModeWriteReplicationCount {get;set;}
public TimeSpan MongoSafeModeWriteTimeout {get;set;}
}
}
我得到一個配置對象,其中MongoDbSettings爲null,我寧願在這種情況下得到一個懷疑。這是可能的嗎?
好的,感謝您的答覆,並感謝您使ServiceStack :-) – ssn
NP和謝謝:-) – mythz