嘗試在Python中解析JSON。ValueError:期望的屬性名稱[重復(fù)]
那絕對(duì)不是JSON-無(wú)論如何都不是上面打印的。它已經(jīng)被解析為Python對(duì)象-JSON具有false,not False和不會(huì)像uunicode一樣顯示字符串(所有JSON字符串都是unicode)。您確定您尚未將json字符串免費(fèi)轉(zhuǎn)換為鏈中某處的Python對(duì)象,因此將其加載到j(luò)son.loads()顯然是錯(cuò)誤的,因?yàn)閷?shí)際上它不是字符串?
解決方法我正在嘗試將JSON對(duì)象解析為Python dict。我從沒做過(guò) 當(dāng)我搜索這個(gè)特定錯(cuò)誤( 第一個(gè)字符有什么問(wèn)題嗎?)時(shí),其他帖子都說(shuō)正在加載的字符串實(shí)際上不是JSON字符串。我很確定這是。
在這種情況下,eval()效果很好,但是我想知道是否有更合適的方法?
注意: 該字符串直接通過(guò)ptt工具來(lái)自Twitter。
>>> import json>>> line = ’{u’follow_request_sent’: False,u’profile_use_background_image’: True,u’default_profile_image’: False,u’verified’: False,u’profile_sidebar_fill_color’: u’DDEEF6’,u’profile_text_color’: u’333333’,u’listed_count’: 0}’>>> json.loads(line)Traceback (most recent call last): File '<stdin>',line 1,in <module> File '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py',line 326,in loads return _default_decoder.decode(s) File '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py',line 366,in decode obj,end = self.raw_decode(s,idx=_w(s,0).end()) File '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py',line 382,in raw_decode obj,end = self.scan_once(s,idx) ValueError: Expecting property name: line 1 column 1 (char 1)
相關(guān)文章:
1. phpstudy apache開啟ssi使用詳解2. vue3+ts+elementPLus實(shí)現(xiàn)v-preview指令3. Xml簡(jiǎn)介_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理4. JSP之表單提交get和post的區(qū)別詳解及實(shí)例5. 詳解瀏覽器的緩存機(jī)制6. xml中的空格之完全解說(shuō)7. jsp實(shí)現(xiàn)登錄驗(yàn)證的過(guò)濾器8. jsp文件下載功能實(shí)現(xiàn)代碼9. 使用Hangfire+.NET 6實(shí)現(xiàn)定時(shí)任務(wù)管理(推薦)10. 如何在jsp界面中插入圖片
