Question: Twice in the books Daenerys has been in situations where it is reasonable to expect that she would have been burned to death, or at least seriously injured, yet has come out unharmed.

The first time was when she stepped into the funeral pyre of Khal Drogo, which resulted in her dragon eggs hatching. The second time is in *A Dance with Dragons*, when she is exposed to Drogon's fire.

In both instances, all that happens to her is her hair is burned away.

I can't be certain, but I believe there may have been references in the first book to her touching burning coals and other hot materials, as well.

Is this a trait shared by other Targaryens? Her brother certainly wasn't immune to molten gold, and while a number of Targaryens were fascinated with fire (Aerion Targaryen died from drinking wildfire, believing it would turn him into a dragon), I don't recall seeing mention of any Targaryen shrugging off fire.

Is Daenerys' apparent immunity explained anywhere?

Answer: 
It does seem to be a regressive genetic trait, if it is a genetic trait, as it is not shared by all Targaryens. There are a few allusions to her apparent heat resistant qualities before the funeral pyre and the hatching of the dragons: most clear is the scene where she picks up the dragon egg that she had placed in the coals in her tent. Her hands are untouched while her handmaiden burns hers after a much shorter contact. In the book, but not in the tv series, it is mentioned she likes her bath to be hotter than most people would find tolerable. 

The other explanation is that it is Magic (add tinkly music) - the first instance when she is clearly fireproof is the funeral pyre scene. This is meant to be a magical event, though no spells are read out nor is there magic lightning effects. Magic in the world of GoT is purposefully ambiguous, not unlike Tolkien's world - there is no neat explanation anywhere what it does and does not do or how many kilojoules of willpower are needed for an effect of magnitude X. However it has been alluded that the re-emergence of dragons has made magic a more potent force everywhere

So it is largely open to interpretation my the reader/watcher, I would guess it is a bit of both. Daenerys is heat resistant by her blood heritage, but the effect is magnified by her magical link to the dragons.
Unfortunately I'm still in the middle of Dance of the Dragons so can't comment on the second, but I came away from the first incident with the distinct impression that the magic of the dragons themselves were protecting her. In other words, she didn't have an inherent immunity but in the dragons' immediate presence she is effectively immune.