This commit is contained in:
clowwindy
2014-11-08 00:22:23 +08:00
parent 0eb0e8c9e6
commit 0a21d8a4ae
3 changed files with 16 additions and 6 deletions
+14 -4
View File
@@ -43,11 +43,8 @@ namespace shadowsocks_csharp.Model
{
try
{
var json = "[0,1,2]";
var result = SimpleJson.SimpleJson.DeserializeObject<List<int>>(json);
string configContent = File.ReadAllText(CONFIG_FILE);
Configuration config = SimpleJson.SimpleJson.DeserializeObject<Configuration>(configContent);
Configuration config = SimpleJson.SimpleJson.DeserializeObject<Configuration>(configContent, new JsonSerializerStrategy());
config.isDefault = false;
return config;
}
@@ -129,5 +126,18 @@ namespace shadowsocks_csharp.Model
throw new ArgumentException("server can not be blank");
}
}
private class JsonSerializerStrategy : SimpleJson.PocoJsonSerializerStrategy
{
// convert string to int
public override object DeserializeObject(object value, Type type)
{
if (type == typeof(Int32) && value.GetType() == typeof(string))
{
return Int32.Parse(value.ToString());
}
return base.DeserializeObject(value, type);
}
}
}
}