Malicious data attacks have raised widespread concerns on data integrity and security of cyber-physical systems. This paper discusses a state recovery problem, where the underlying cyber-physical system is subject to switching location attacks. Compared with the fix location attack, the switching location attack changes the attack locations at a constant/variable frequency. This paper develops nonzero sub-row and nonzero entry sparsity models to characterize the switching location attacks. Moreover, state recovery constraints are deduced for different attack modes, which prove the higher efficient state recovery compared with the fix location and static decoders. According to the different sparsity models, l1=l2 and l1 decoders are designed, respectively, which can recover the initial state accurately within relaxation conditions. Numerical simulations in a randomly chosen system and a 14-bus electric power system show the proposed dynamic decoders can provide effective system resilience under switching location attacks.