Parsing JSON-file with Python in Django -
i have query fetch json-file , want show data in table in html. error: typeerror: string indices must integers in line: 'status': item['status'],. problem outer brackets, because missing in json or what?
views.py code
json_obj = urllib2.urlopen(url) data = json.load(json_obj) results = [] item in data: results.append({ 'status': item['status'], 'device': item['device'], }) return render(request, 'index/index.html', {'objects_list': results})
json-file:
{ “version": “3.62”, "treesize": 2, "": [ { “status”: “up”, "device": “somedevicename1”, } { “status”: “up”, "device": “somedevicename2”, }] }
i don't know whether accidentally copied json content wrong or not should is:
>>> item in data[""]: ... results.append({ ...
Comments
Post a Comment