You'll need to check visas here - you need a transit visa (which costs money!) if your wait is longer than 24 hours in China. I don't know if this is cumulative (as you're staying at Nanjing AND Beijing) or if it's "per" wait; presumably the border guards won't check passport/visas if it's internal, but China is hardly the country to be in when slipping up with visas