Python has its own module for handling python, which can be directly import JSON when used. Using the loads method, you can convert a JSON string into a Python object, as follows:
JSON Python
Object Dict
Array list
String Unicode
Number (int) int, long
Number (real) float
True True
False false
Null None
However, when using the JSON module, it is necessary to pay attention to the processing of Chinese, loads method if the encoding of the incoming string is not UTF-8, you need to use encoding to specify the character encoding
Copy Code code as follows:
Import JSON
Import Base64
f = Open ("./result_diff.txt")
For L in F:
Try
fp = L[l.find ("? FP") +1:]
Http = Fp.find ("http/")
fp = fp[3:http-1]
fp = Fp.decode ("GBK"). Encode ("Utf-8")
STR1 = json.loads (FP, encoding= "Utf-8")
Print str1
Except Exception, E:
Print str (e)
When the FP contains Chinese and is GBK encoded, when we convert the current line encoding to UTF8, we need to specify the encoding when using JSON for decoding.
Or so
Copy Code code as follows:
Directly into the GBK encoding, you do not have to specify the encoding type of JSON, you do not use the encoding parameter
PS: About JSON operation, here we recommend a few more practical JSON online tools for your reference to use:
Online JSON code inspection, inspection, landscaping, formatting tools:
Http://tools.jb51.net/code/json
JSON Online formatting tool:
Http://tools.jb51.net/code/jsonformat
Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson
JSON code online Format/beautify/compress/edit/Convert tools:
Http://tools.jb51.net/code/jsoncodeformat
Online JSON compression/escape tool:
Http://tools.jb51.net/code/json_yasuo_trans
C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_json