Usually my webservice built with Bottle return JSON files, which works fine. But, I've an exception that need to call a local function.
Here is what I tried to do:
import json
def getData():
return json.dumps({'data': someData })
def function():
try:
# Fail
except:
print getData()
print type(getData())
json.load(getData())
So it prints:
{"data": "myData"}
<type 'str'>
[...]
AttributeError: 'str' object has no attribute 'read'
So json.dumps gives me a string. How can I use it as JSON ?
returnin front ofjson?return.someDatais already adict()you just accesssomeData... at least it should be. If it's a string then you need to calljson.load()on itdictbecause of the{ ... }, but it's actually a string.