fixed. please try it

On Monday, 16 July 2012 14:56:16 UTC-5, Derek wrote:
>
> Jsondecoder does not accept Decimal objects. Take a look at 
> serializers.py. You could try converting to float.
>
> See here for workarounds...
>
> http://stackoverflow.com/questions/1960516/python-json-serialize-a-decimal-object
>  
>
> On Monday, July 16, 2012 7:34:25 AM UTC-7, Vineet wrote:
>>
>> Hi !
>> From a controller, I am trying to return a jsonified resultset (obtained 
>> by executing sql directly).
>>
>> resultset = ( ('201207020920', Decimal('5308.20'), Decimal('5308.20'), 
>> Decimal('5288.00'), Decimal('5292.40'), ...)
>>
>> ## convertd it to list of lists
>>
>> list_of_tuples = list(resultset)
>> list_of_lists = [list(i) for i in list_of_tuples]
>>
>> ## Since an error is thrown as under--
>>
>> TypeError: Decimal('5308.20') is not JSON serializable
>>
>>
>> ## convertd all list items decimal to str ---
>>
>> for x in list_of_lists:
>>         for y in x:
>>             y = str(y)
>>             print y, 'type of this y is ', type(y)
>>
>> ## confirmed that all are of type 'str'
>>
>> D = dict(list_of_lists = list_of_lists)
>> return response.json(D)
>>
>> Still, the same error is thrown as under--
>>
>> TypeError: Decimal('5308.20') is not JSON serializable
>>
>> How do I fix this?
>>
>> Thanks,
>>
>> Vineet
>>
>>

-- 



Reply via email to