Just how dirty is the hat?
If it's dirty to the point of gross, then just get a new one. If it's just got some light dirt on it, take a moist handtowel, maybe a little detergent (regular soap is likely to kill the color of it) and rub it a little bit at a time. Wait till that portion dries, then do some more. That will keep it from deforming.
If the hat has cardboard instead of plastic inside the bill, then I wouldn't wash it in the washer. If the bill gets soaked, then it probably will never dry right, even with the frame thingy.