I. Use of file JSONJSON introduction: JSON Full name JavaScripts object Notation, is a lightweight data interchange format, the most extensive application of JSON as a Web server and client communication in AIAX data format, is now also used in httpd requests, So the various learning of JSON is a natural thing. The following are the two most common ways of working in peacetime. #/usr/bin/python#coding =utf-8# @Time: 2017/11/12 22:27# @Auther: Liuzhenchuan# @File: json-on. PY#1. Four ways to JSON# json.loads#json. Dumps#多了个s is the processing of the string, no S is processing the file# Json.load#json. Dump#解释 load/loads: Loads the meaning. is to convert JSON into other formats, strings or file-related#解释: dump/dumps: Upside-down meaning. is to convert other objects or formats into JSON format .#自动解析javascript的网址: json.cn #示例1: Convert python dict format to string formatImport JSON print ' # # # # #json. Dumps () method converts a dictionary to a string format ##### ' A =Dict(name= Lzc ' ,age= ,message= "You're so Corde '" Span style= "Font-family:simsun, Stsong; Font-size:18px ">) print a print type(a) B = Json.dumps (a)print type(b) print b #示例2:print ' # # # # #json. Loads () method converts a string into a dictionary but the encoding is converted to UNIC encoded ##### ' print type(b) C = json.loads (b)print type(c) print c >>># # # # # # # #json Dumps () method converts a dictionary to a string format #####{' message ': ' Corde ', ' age ': ' + ', ' name ': ' Lzc '}<type ' dict ' ><type ' str ' >{"message": "Corde", "Age": "+", "name": "Lzc"}# # # # # # # # # #json the loads () method converts a string into a dictionary but the encoding is converted to UNIC encoding #####<type ' str ' ><type ' dict ' >{u ' message ': U ' corde ', U ' age ': U ' ", U ' name ': U ' lzc '}
Python Foundation 7.7 json--on