如果您不知道数据是文件还是字符串...使用
import StringIO as io
youMagicData={
results:[...],
"max_id":1346534,
"since_id":0,
"refresh_url":"?since_id=26202877001&q=twitter",
.
.
.
}
magicJsonData=json.loads(io.StringIO(str(youMagicData)))#this is where you need to fix
print magicJsonData
#viewing fron the center out...
#youMagicData{}>str()>fileObject>json.loads
#json.loads(io.StringIO(str(youMagicData))) works really fast in my program and it would work here so stop wasting both our reputation here and stop down voting because you have to read this twice
来自[https://docs.python.org/3/library/io.html#text-i-o]
来自python内置库的json.loads,json.loads需要一个文件对象,并且不检查传递的内容,因此它仍然对传递的内容调用read函数,因为该文件对象仅在您调用read()时才放弃数据 。 因此,由于内置的字符串类不具有读取功能,因此需要包装器。 因此,简而言之,StringIO.StringIO函数将字符串类和文件类子类化,并且将内部工作划分为网格可听到我的低细节重建[https://gist.github.com/fenderrex/843d25ff5b0970d7e90e6c1d7e4a06b1]所以最后,就像编写一个ram文件并在一行中将其json....。