Japanese encephalitis virus (JEV) is regarded as an emerging and reemerging pathogen that is a primary cause of viral encephalitis in humans. However, there is a scarcity of research on the prevalence of JEV genotypes across the different mosquito species in Shanghai. In this study, the diversity of mosquito species and prevalence of JEV in pig and sheep farms in Shanghai were surveyed in 2022. A total of 24,073 mosquitoes, belonging to four genera and seven species, were collected from pig and sheep enclosures in the Chongming, Jiading, Pudong, Fengxian, and Jinshan Districts of Shanghai. Culex tritaeniorhynchus was identified as the predominant species (87.09%, 20,965/24,073) with the highest JEV detection rate. Six strains of JEV were isolated in this study, and genetic analysis revealed that five strains (SH22-M5, SH22-M9, SH22-M14, SH22-M41, and SH22-M52) belonged to genotype I (GI), while one strain (SH22-M1) was classified as genotype III (GIII). The sequence homology was highest between SH22-M9 and SD-1 (99.87%) and between SH22-M14 and SD12 (99.53%). SH22-M5, SH22-M41, and SH22-M52 shared the highest sequence homology with the HEN07011 strain (99.73–99.93%). SH22-M1 was most closely related to SH18, with a sequence homology of 99.8%. Additionally, for the first time, the GI JEV strain was isolated from mosquitoes in sheep sties in this study. The findings highlight the necessity of enhancing the surveillance of JEV in pigs and other livestock farms, including sheep, as well as monitoring the mosquitoes present in these environments. It is recommended that livestock farming areas be kept separate from human habitation to reduce the risk of JEV infections in humans.