Unable to parse json data written directly by python json.dump() -
i have following function:
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
that tells me file indeed exist, , trying read txt file contains json.
the json written following call:
def writetable(table,reference_name): open(reference_name + ".txt","w") text_file: json.dump(table, text_file)
yet when go readtable
following error:
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 decoded") valueerror: no json object decoded
and data in file looks this:
[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]
Comments
Post a Comment