The concentrations of D-Proline (D-Pro) and D-Alanine (D-Ala) in the saliva of early-stage gastric cancer patients are prominently higher than those of healthy people. Therefore, precisely monitoring the concentrations of D-Pro and D-Ala has essential implications for gastric cancer diagnosis and treatment. Here, through pyrolysis of ZIF-8 precursor filled with glucose (G@ZIF-8), the carbon dots confined in N-doped carbon (CDs@NC) are successfully obtained. The CDs@NC can readily act as peroxidase-like nanozyme for the colorimetric detection of D-amino acids that associated with early gastric cancer. Intriguingly, the peroxidase-like activity of CDs@NC can be tuned easily by adjusting the content of glucose precursors. Further study of the catalytic mechanism shows that the superoxide radical (O2−) may be the critical Reactive oxygen species (ROS) involved in the peroxidase-like catalytic reactions. The excellent results of saliva tests suggest that the colorimetric method could be used to quickly distinguish patients with early gastric cancer from healthy people.