在研究webService的時候,須要將參數列表化,如將'["123","456"]'轉化爲["123","456"],須要使用到json.loads()python
因爲python並不怎麼區分" 和 ', 因此本人歷來都是用',由於不用按shift。(懶癌晚期)web
可是在json這個庫中,若是不加區分,會出現問題,以下圖:json
print json.loads("['123','456']") # print json.loads('["123", "123"]')
執行後會報錯:flask
C:\Python27\python.exe E:/repository/flask_webService/test.py Traceback (most recent call last): File "E:/repository/flask_webService/test.py", line 22, in <module> print json.loads("['123','456']") File "C:\Python27\lib\json\__init__.py", line 338, in loads return _default_decoder.decode(s) File "C:\Python27\lib\json\decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded
可是執行下面的語句:函數
# print json.loads("['123','456']") print json.loads('["123", "123"]')
顯示結果爲code
C:\Python27\python.exe E:/repository/flask_webService/test.py [u'123', u'123'] Process finished with exit code 0
最後總結就是,若是使用json.loads()這個函數,須要在待轉換字符串中使用雙引號。字符串