Using agricultural and forestry wastes as raw materials, adsorbent materials were prepared for dye adsorption in wastewater, which can minimize the environmental load and fully realize sustainability by treating waste with waste. Taking lignosulfonate as a raw material, due to its molecular structure having more reactive groups, it is easy to form composite materials via a chemical oxidation reaction with an aniline monomer. After that, using a sodium lignosulfonate/polyaniline composite as the precursor, the activated high-temperature pyrolysis process is used to prepare porous carbon materials with controllable morphology, structure, oxygen, sulfur, and nitrogen content, which opens up a new way for the preparation of functional carbon materials. When the prepared O-N-S co-doped activated carbon materials (SNC) were used as adsorbents, the adsorption study of cationic dye methylene blue was carried out, and the removal rate of SNC could reach up to 99.53% in a methylene blue solution with an initial concentration of 100 mg/L, which was much higher than that of undoped lignocellulosic carbon materials, and the kinetic model conformed to the pseudo-second-order kinetic model. The adsorption equilibrium amount of NC (lignosulfonate-free) and SNC reached 478.30 mg/g and 509.00 mg/g, respectively, at an initial concentration of 500 mg/L, which was consistent with the Langmuir adsorption isothermal model, and the adsorption of methylene blue on the surface of the carbon material was a monomolecular layer. The adsorption of methylene blue dye on the carbon-based adsorbent was confirmed to be a spontaneous and feasible adsorption process by thermodynamic parameters. Finally, the adsorption of SNC on methylene blue, rhodamine B, Congo red, and methyl orange dyes were compared, and it was found that the material adsorbed cationic dyes better. Furthermore, we also studied the adsorption of SNC on different kinds of heavy metal ions and found that its adsorption selectivity is better for Cr3+ and Pb2+ ions.