嘗試在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。我從沒(méi)做過(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. Python實(shí)現(xiàn)迪杰斯特拉算法過(guò)程解析2. Python如何進(jìn)行時(shí)間處理3. 詳解Python模塊化編程與裝飾器4. python使用ctypes庫(kù)調(diào)用DLL動(dòng)態(tài)鏈接庫(kù)5. Python中l(wèi)ogger日志模塊詳解6. html小技巧之td,div標(biāo)簽里內(nèi)容不換行7. 以PHP代碼為實(shí)例詳解RabbitMQ消息隊(duì)列中間件的6種模式8. python裝飾器三種裝飾模式的簡(jiǎn)單分析9. python web框架的總結(jié)10. Python 日期與時(shí)間轉(zhuǎn)換的方法
