Python ValueError: No JSON object could be decoded -



Python ValueError: No JSON object could be decoded -

i'm trying read json , values. have folder json's archives, , need open archives , values them.

this code:

# -*- encoding: utf-8 -*- pprint import pprint import json import os def start(): dirname, dirnames, filenames in os.walk('test'): filename in filenames: json_file = open(os.path.join(dirname, filename)).read() # json_file = unicode(json_file, 'utf-8') json_data = json.loads(json_file) pprint(json_data) key, value in json_data.items(): print "key : ", key print "value: ", value start()

this 1 of json's

{ "test" : "search user 1", "url" : "http://127.0.0.1:8000/api/v1/user/1/?format=json", "status_code" : 200, "method" : "get" }

but when run it, this:

valueerror: no json object decoded

what hell wrong? yesterday working now, or crazy

i tried way:

from pprint import pprint import json import os dirname, dirnames, filenames in os.walk('test'): filename in filenames: json_file_contents = open(os.path.join(dirname, filename)).read() try: json_data = json.loads(json_file_contents) except valueerror, e: print e print "error"

i cant see error '-'

for filename in filenames: open(os.path.join(dirname,filename)) fd: json_data = fd.read() print json_data

this way can see json files contain, can't utilize illustration access key, json_data['url']

it's possible .read() method moving cursor end of file. try:

for filename in filenames: open(os.path.join(dirname,filename)) fd: json_data = json.load(fd)

and see gets you.

python json

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -