注意:我已在此Feed的底部提供了解决方案.
我有一个C#Win 8应用程序,我正在反序列化一些看起来像这样的json:
{
'Unit': [
{
'name':'House 123',
isAvailable:'no'
},
{
'name':'House 456',
isAvailable:'yes'
}]
}
Run Code Online (Sandbox Code Playgroud)
进入使用此接口的类:
public interface IUnit
{
string Name { get; }
bool isAvailable { get; }
}
Run Code Online (Sandbox Code Playgroud)
但是牛顿软件会抛出一个错误:
解析值时遇到意外的字符:n.Path'Unit [0] .isAvailable,第1行,第42位.
有没有办法根据生成的对象属性类型bool扩展Newtonsoft来解析yes/no或1/0?现在它只适用于真/假.
关于类的自定义转换器有几个帖子,但不是像bool这样的原始类型.
有什么建议?
谢谢你的期待.我对Ninject很新,到目前为止还喜欢它.我得到了在调试模式下绑定一个东西并在发布模式下绑定另一个东西的部分.那些是全局绑定,你必须使用Ninjects示例代码声明每个Samurai都有剑或匕首.它不是/或者是一个或另一个.
我怎么做我可以拥有一把带武器的武士,另一把带有匕首的地方,如果他们愿意,他们甚至可以换武器.除了创建一堆具有不同绑定模块的内核之外,还有其他方法吗?
以下是Ninject的示例代码.如果你把它放在一个控制台应用程序中,它应该运行:
using System;
using Ninject;
namespace NinjectConsole
{
class Program
{
//here is where we have to choose which weapon ever samurai must use...
public class BindModule : Ninject.Modules.NinjectModule
{
public override void Load()
{
//Bind<IWeapon>().To<Sword>();
Bind<IWeapon>().To<Shuriken>();
}
}
class Shuriken : IWeapon
{
public void Hit(string target)
{
Console.WriteLine("Pierced {0}'s armor", target);
}
}
class Sword : IWeapon
{
public void Hit(string target)
{
Console.WriteLine("Chopped {0} clean in half", target);
}
}
interface IWeapon
{
void Hit(string …Run Code Online (Sandbox Code Playgroud)