You can work out the particles in an ion from its atomic number and mass number. The number of protons is equal to the atomic number. The number of neutrons is the mass number minus the atomic number. Neither of these changes when an atom forms an ion.
The number of electrons does change. A neutral atom has the same number of electrons as protons. A positive ion has fewer electrons than protons, so take the charge away from the number of protons. A negative ion has more electrons than protons, so add the charge to the number of protons.
Magnesium has atomic number 12 and mass number 24. A magnesium ion with a 2+ charge has 12 protons, 24 - 12 = 12 neutrons and 12 - 2 = 10 electrons. Oxygen has atomic number 8 and mass number 16. An oxide ion with a 2- charge has 8 protons, 8 neutrons and 8 + 2 = 10 electrons. Chlorine has atomic number 17 and mass number 35, so a chloride ion with a 1- charge has 17 protons, 18 neutrons and 18 electrons.