Every culture is different: In some countries on the American continent, the locals will refuse to have their photos taken for fear of ‘having their souls taken away’. It may be a true belief, or just an excuse to get money from tourists.
In other countries people don’t mind having their photos taken. I find that in China, generally speaking, most people are ok with it, as long as you are respectful. Even if you don’t speak the language, make an effort to communicate. Sometimes a simple smile, a nod, a gesture, lifting up your camera and asking ‘Is it ok if I take your picture?’ is enough to make yourself understood.
But taking photos of strangers on the street can be quite difficult. There are two main ways of doing it: “Street Photography” style, where you try to steal a photo without the person noticing; or “Portrait Photography” style, where you approach them, engage with them and then take a photo.

If I go to a hutong, for example, to take some nice photos of the locals, I usually spend some time walking around, soaking up the place, trying to get a feel for it. It helps to let people see me and get used to my presence. Then I take out my camera, find a good spot and wait for the right moment. I take my time to understand the environment, because it always ends in better images. On several occasions I have been invited to go inside people’s houses, with smiles, giggles and offerings of tea.
If you decide to approach the person and ask permission, don’t be afraid that they will say “No,” chances are, they will agree. But if you get a negative response, don’t insist – it will only upset them. If you have their permission, after spending a few moments using your people skills and engaging with them, you can think about technical things like composition, lighting, clean background, etc.
Another good way to take photos of strangers is to buy something. You were probably thinking of buying a snack or souvenir anyway and once you have had that short interaction with the vendor, you can ask them to pose for a photo and they usually they won’t refuse.
It may not always be possible to ask permission and it is totally alright to take pictures of people without them noticing. For example, you may see a picture-perfect situation and if you stop and ask permission, the moment is gone.