object = {'score-set': [('SomeString', 1.0)], 'n': 10, 'num-found': 1, 'start': 0}
type(object) is dict.
When I do this in the command line
json.dump(object,f)
where f is an writable open file. I get the dump in the file perfectly.
But inside a program in a context like this:
def JSONresponse(object,request,jsonIndent=None):
r=HttpResponse(mimetype="application/json")
callback1=request.GET["jsoncallback"] if "jsoncallback" in request.GET else None
callback2=request.GET["callback"] if "callback" in request.GET else None
callback = callback1 or callback2
if callback and len(callback) > 1:
r.write(callback + "(")
json.dump(object,r,indent=jsonIndent)
r.write(");")
else:
json.dump(object,r,indent=jsonIndent)
r.write("\n")
return r
I get the following exception on the json.dump line.
Exception Value: 1.0 is not JSON serializable
Any hints would be much appreciated,
Thanks a lot,
I’m guessing your
floatisn’t really afloat, but acts like it in certain ways. Try converting it to afloatbefore serializing it: