A two-degree-of-freedom and three-degree-of-freedom switchable ball joint structure, comprising: an outer shell with an accommodating cavity; a hollow sphere, which is located in the accommodating cavity of the outer shell and is rotatable in the accommodating cavity, wherein the lower hemispherical surface of the sphere is provided with a groove with a symmetrical center plane located on the vertical center plane of the sphere; a limiting pin, which is vertically inserted in the outer shell and located below the sphere, and the axis line of which passes through the center of the sphere; a first worm gear assembly, which is provided in the outer shell for driving the limiting pin to make a linear reciprocating motion in the vertical direction; wherein the first worm gear assembly drives the top of the limiting pin to be inserted into or exit from the groove to realize the adjustment of the degree of freedom of rotation of the sphere; the two-degree-of-freedom and three-degree-of-freedom switchable ball joint structure further comprises a torsion spring assembly which is provided in the hollow cavity of the sphere and matches with the top of the limiting pin so that the sphere is reset; the torsion spring assembly comprises a torsion spring seat fastened to the hollow cavity of the sphere, a torsion spring having a first support arm and a second support arm and pivotally connected to the torsion spring seat through a pivot shaft, and a limiting bolt fastened to the torsion spring seat and located between the first support arm and the second support arm, wherein the pivot axis of the torsion spring is perpendicular to the vertical center plane where the groove is located, when the top of the limiting pin is inserted into the groove and rotates the sphere, the limiting pin pushes the first support arm or the second support arm along the distribution direction of the groove. an outer shell with an accommodating cavity; a hollow sphere, which is located in the accommodating cavity of the outer shell and is rotatable in the accommodating cavity, wherein the lower hemispherical surface of the sphere is provided with a groove with a symmetrical center plane located on the vertical center plane of the sphere; a limiting pin, which is vertically inserted in the outer shell and located below the sphere, and the axis line of which passes through the center of the sphere; a first worm gear assembly, which is provided in the outer shell for driving the limiting pin to make a linear reciprocating motion in the vertical direction; wherein the first worm gear assembly drives the top of the limiting pin to be inserted into or exit from the groove to realize the adjustment of the degree of freedom of rotation of the sphere; the two-degree-of-freedom and three-degree-of-freedom switchable ball joint structure further comprises a torsion spring assembly which is provided in the hollow cavity of the sphere and matches with the top of the limiting pin so that the sphere is reset; the torsion spring assembly comprises a torsion spring seat fastened to the hollow cavity of the sphere, a torsion spring having a first support arm and a second support arm and pivotally connected to the torsion spring seat through a pivot shaft, and a limiting bolt fastened to the torsion spring seat and located between the first support arm and the second support arm, wherein the pivot axis of the torsion spring is perpendicular to the vertical center plane where the groove is located, when the top of the limiting pin is inserted into the groove and rotates the sphere, the limiting pin pushes the first support arm or the second support arm along the distribution direction of the groove.