Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法解析python json.dump()直接写入的json数据_Python_Json - Fatal编程技术网

无法解析python json.dump()直接写入的json数据

无法解析python json.dump()直接写入的json数据,python,json,Python,Json,我有以下功能: def readTable(self,reference_name): p = self.base_path + reference_name + ".txt" if os.path.exists(p): print p else: print "oops" f = open(p, "r") data = json.loads(f.read()) self.main_table = data

我有以下功能:

def readTable(self,reference_name):

    p  = self.base_path + reference_name + ".txt"

    if os.path.exists(p):
        print p
    else:
        print "oops"

    f = open(p, "r")
    data = json.loads(f.read())
    self.main_table =  data
这告诉我该文件确实存在,并且正在尝试读取包含json的txt文件

json由以下调用编写:

def writeTable(table,reference_name):

    with open(reference_name + ".txt","w") as text_file:
        json.dump(table, text_file)
然而,当我转到
readTable
时,我得到以下错误:

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd_comm.py", line 1069, in doIt
    result = pydevd_vars.evaluateExpression(self.thread_id, self.frame_id, self.expression, self.doExec)
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd_vars.py", line 341, in evaluateExpression
    Exec(expression, updated_globals, frame.f_locals)
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd_exec.py", line 3, in Exec
    exec exp in global_vars, local_vars
  File "<string>", line 1, in <module>
  File "C:\Users\user\AppData\Local\Continuum\Anaconda\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda\lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\user\AppData\Local\Continuum\Anaconda\lib\json\decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

您的json是什么样子的?格式正确吗?您可以通过jsonlint.com检查您的JSON中有一个
u'
,这是无效的。是否确实仅使用
json.dump
创建了该文件?该文件中没有json。您为它编写了一个Python列表,列表中有
u'',
。该文件不是用
json.dump()
创建的,而是用
f.write(str(table))
创建的。非常感谢。在修改了ipy之后,我忘记了在ipy中重新运行一些python代码。请贴出答案。
[12.7451, 0.774784, 3.422666, 1.21522, 0.918463, 630.693, 6.37, 6.263, 2479.94, 555.475, 24.3585, 6.619372, 8.58075, 1.12385, 1.555879, 7.75208, 274.995, 14458.4, 3.8407999999999998, 68.25702, 119.12, 104.5, 1105.223, 10.1126, u'', 15.8013, 3.7115, 7.612444, 0.71116, 3.34583, 45.645, 3.6949300000000003, 57.5855, 8.22703, 1.3449900000000001, 26.80494, 34.639, 2.95794, 30.6675, u'', 12.86649]