Molecular hydrogen in H II regions in the Magellanic Clouds