In Japan it happened rather quickly, as The Emperor "supported" the US occupation, which gave it divine legitimacy, and MacArthur's governance of Japan was rather enlightened. In Germany...I don't really know, but I suspect the Russian threat to the east gave the West Germans additional motivation to accept foreign troops.
In any case, I'd say both were special cases, and probably the exception rather than the rule. The rule, I'd think, is more like Vietnam, Napoleonic Spain, the USSR in Afghanistan...