首页 > 解决方案 > 动态对象反序列化到类

问题描述

所以这在过去一两天一直困扰着我,我就是不知道为什么会这样。

目前,我正在尝试将动态对象反序列化为一个类以供使用。但由于某种原因,我收到此错误:(我的班级)有一些无效参数。我用来反序列化的代码:

dynamic BaseOffsets = JsonConvert.DeserializeObject(File.ReadAllText(Environment.CurrentDirectory + @"\Offsets.json"));
            Netvars = JsonConvert.DeserializeObject<netvars>(BaseOffsets.netvars);
            Signatures = JsonConvert.DeserializeObject<signatures>(BaseOffsets.signatures);

所以,首先,我检查了类的值。他们都一一对应。但是,调试器仍然告诉我类中有一个神奇的额外变量。即使在直接比较之后,我也无法在任何一个类中找到它导致它的变量。

然后我分解了JSON结构,看看是否有我遗漏的东西。但是没有变量仍然是相同的。我的班级代码:

public class netvars
{
    public Int32 m_ArmorValue { get; set; }
    public Int32 m_Collision { get; set; }
    public Int32 m_CollisionGroup { get; set; }
    public Int32 m_Local { get; set; }
    public Int32 m_MoveType { get; set; }
    public Int32 m_OriginalOwnerXuidHigh { get; set; }
    public Int32 m_OriginalOwnerXuidLow { get; set; }
    public Int32 m_aimPunchAngle { get; set; }
    public Int32 m_aimPunchAngleVel { get; set; }
    public Int32 m_bGunGameImmunity { get; set; }
    public Int32 m_bHasDefuser { get; set; }
    public Int32 m_bHasHelmet { get; set; }
    public Int32 m_bInReload { get; set; }
    public Int32 m_bIsDefusing { get; set; }
    public Int32 m_bIsScoped { get; set; }
    public Int32 m_bSpotted { get; set; }
    public Int32 m_bSpottedByMask { get; set; }
    public Int32 m_clrRender { get; set; }
    public Int32 m_dwBoneMatrix { get; set; }
    public Int32 m_fAccuracyPenalty { get; set; }
    public Int32 m_fFlags { get; set; }
    public Int32 m_flFallbackWear { get; set; }
    public Int32 m_flFlashDuration { get; set; }
    public Int32 m_flFlashMaxAlpha { get; set; }
    public Int32 m_flNextPrimaryAttack { get; set; }
    public Int32 m_hActiveWeapon { get; set; }
    public Int32 m_hMyWeapons { get; set; }
    public Int32 m_hObserverTarget { get; set; }
    public Int32 m_hOwner { get; set; }
    public Int32 m_hOwnerEntity { get; set; }
    public Int32 m_iAccountID { get; set; }
    public Int32 m_iClip1 { get; set; }
    public Int32 m_iCompetitiveRanking { get; set; }
    public Int32 m_iCompetitiveWins { get; set; }
    public Int32 m_iCrosshairId { get; set; }
    public Int32 m_iEntityQuality { get; set; }
    public Int32 m_iFOVStart { get; set; }
    public Int32 m_iGlowIndex { get; set; }
    public Int32 m_iHealth { get; set; }
    public Int32 m_iItemDefinitionIndex { get; set; }
    public Int32 m_iItemIDHigh { get; set; }
    public Int32 m_iObserverMode { get; set; }
    public Int32 m_iShotsFired { get; set; }
    public Int32 m_iState { get; set; }
    public Int32 m_iTeamNum { get; set; }
    public Int32 m_lifeState { get; set; }
    public Int32 m_nFallbackPaintKit { get; set; }
    public Int32 m_nFallbackSeed { get; set; }
    public Int32 m_nFallbackStatTrak { get; set; }
    public Int32 m_nForceBone { get; set; }
    public Int32 m_nTickBase { get; set; }
    public Int32 m_rgflCoordinateFrame { get; set; }
    public Int32 m_szCustomName { get; set; }
    public Int32 m_szLastPlaceName { get; set; }
    public Int32 m_thirdPersonViewAngles { get; set; }
    public Int32 m_vecOrigin { get; set; }
    public Int32 m_vecVelocity { get; set; }
    public Int32 m_vecViewOffset { get; set; }
    public Int32 m_viewPunchAngle { get; set; }
}

public class signatures
{
    public Int32 dwClientState { get; set; }
    public Int32 dwClientState_GetLocalPlayer { get; set; }
    public Int32 dwClientState_IsHLTV { get; set; }
    public Int32 dwClientState_Map { get; set; }
    public Int32 dwClientState_MapDirectory { get; set; }
    public Int32 dwClientState_MaxPlayer { get; set; }
    public Int32 dwClientState_PlayerInfo { get; set; }
    public Int32 dwClientState_State { get; set; }
    public Int32 dwClientState_ViewAngles { get; set; }
    public Int32 dwEntityList { get; set; }
    public Int32 dwForceAttack { get; set; }
    public Int32 dwForceAttack2 { get; set; }
    public Int32 dwForceBackward { get; set; }
    public Int32 dwForceForward { get; set; }
    public Int32 dwForceJump { get; set; }
    public Int32 dwForceLeft { get; set; }
    public Int32 dwForceRight { get; set; }
    public Int32 dwGameDir { get; set; }
    public Int32 dwGameRulesProxy { get; set; }
    public Int32 dwGetAllClasses { get; set; }
    public Int32 dwGlobalVars { get; set; }
    public Int32 dwGlowObjectManager { get; set; }
    public Int32 dwInput { get; set; }
    public Int32 dwInterfaceLinkList { get; set; }
    public Int32 dwLocalPlayer { get; set; }
    public Int32 dwMouseEnable { get; set; }
    public Int32 dwMouseEnablePtr { get; set; }
    public Int32 dwPlayerResource { get; set; }
    public Int32 dwRadarBase { get; set; }
    public Int32 dwSensitivity { get; set; }
    public Int32 dwSensitivityPtr { get; set; }
    public Int32 dwSetClanTag { get; set; }
    public Int32 dwViewMatrix { get; set; }
    public Int32 dwWeaponTable { get; set; }
    public Int32 dwWeaponTableIndex { get; set; }
    public Int32 dwYawPtr { get; set; }
    public Int32 dwZoomSensitivityRatioPtr { get; set; }
    public Int32 dwbSendPackets { get; set; }
    public Int32 dwppDirect3DDevice9 { get; set; }
    public Int32 m_pStudioHdr { get; set; }
    public Int32 m_pitchClassPtr { get; set; }
    public Int32 m_yawClassPtr { get; set; }
}

如果有人可以帮助我,我将不胜感激,我已经搜索了几个小时,但我仍然很困惑。

标签: c#jsonjson.netdeserialization

解决方案


通过仅反序列化主类然后取出两个子类来解决我的问题。这不是我想要的,但它有效


推荐阅读