Outline
①json, what's the use?
② Method Introduction and Small example
JSON is a cross-platform, cross-language interaction, used to convert each other.
Ii. Introduction of methods
1json.loads (str) converts the string form of dict, list, tuple to notional.
Note: Because only other languages double quotes are not representative strings, we use single quotes for our arguments.
Out of the Py language, other languages have no (), so the tuple-type string cannot be converted.
Import Jsona = ' [Hello ', 11,22] ' B = json.loads (a) print (b) #[' Hello ', 11, 22]
Json.dumps (a) a represents the Dict, list, and tuple to convert dict, list, tuple to string.
Note: The tuple will be converted to list, other languages do not say.
Import Jsona = ("Hello", 11,22) b = Json.dumps (a) print (b) #["\u4f60\u597d", 11, 22]
Additional knowledge:
Json.load (Open (' xx ', r)) → convert the string in xx file to notional → Open xx file in R mode.
Json.dump (Yy,open (' xx ', W)) → Convert the object yy to a string → Open the xx file in W, and deposit the converted yy in XX.
Module--json