Freshwater resources have been gradually salinized in recent years, dramatically impacting the ecosystem and human health. Therefore, it is necessary to detect the salinity of freshwater resources. However, traditional detection methods make it difficult to check the type and concentration of salt quickly and accurately in solution. This paper uses a portable near-infrared spectrometer to qualitatively discriminate and quantitatively predict the salt in the solution. The study was carried out by adding ten salts of NaCl, KCl, MgCl2, CaCl2, Na2CO3, K2CO3, CaCO3, Na2SO4, K2SO4, MgSO4 to 2 milliliters of deionized water to prepare a single salt solution (0.02% - 1.00%) totaling 100 sets. It was found that the Support vector machine (SVM) model was only effective in discriminating the class of salt anions in the solution. The Partial least squares-discriminant analysis (PLS-DA) model, on the other hand, can effectively discriminate the classes of salt in solution, and the accuracies of the optimal model prediction set and the interactive validation set are 98.86% and 99.66%, respectively. Furthermore, the Partial least squares regression (PLSR) models can accurately predict the concentration of NaCl, KCl, MgCl2, CaCl2, Na2CO3, K2CO3, CaCO3, Na2SO4, K2SO4, MgSO4 salt solutions. The coefficients of determination R2 of their model interactive validation sets were 0.99, 0.99, 0.99, 0.97, 0.99, 0.99, 0.98, 0.99, 0.98, and 0.98, respectively. This study shows that NIRS can achieve rapid and accurate qualitative and quantitative detection of salts in solution, which provides technical support for the utilization of safe water resources.