What exactly produced that error, and can you show the rest of the 
traceback details?

On Monday, February 24, 2014 10:04:09 PM UTC-5, Brando wrote:
>
> I have json data that looks like this:
>
> [['tom', 324],['dick', 246],['harry', 112]]
>
> I want to be able to display html like follows:
>
> Line: 324 - tom
> Line: 246 - dick
> Line: 112 - harry
>
>
> So....I made a function to reformat my data and use represent to run the 
> data through the function:
>
> Field('username', 'json', represent = lambda usernames, row:displayrecords
> (usernames)),
>
>
> Here is the function:
> def displayrecords(value):
> values = []
> for x, y in value:
> values.append(str('Line: '+ str(y) + ' ~ ' + x))
> return values
>
> This function then give me a list as follows:
>
> ['Line: 324 ~ tom', 'Line: 246 ~ dick', 'Line: 112 ~ harry']
>
>
> Now, whenever I change the field line to this
> Field('username', 'json', represent = lambda usernames, row: 
> XML('<br>'.join(displayrecords(usernames)))),
>
> I get the following traceback:
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
>
> Traceback (most recent call last):
>   File "/Volumes/BrandonsData/Google 
> Drive/web2py/web2py.app/Contents/Resources/gluon/restricted.py", line 217, in 
> restricted
>   File "/Volumes/BrandonsData/Google 
> Drive/web2py/web2py.app/Contents/Resources/applications/Contour/controllers/devices2.py"
>  <http://127.0.0.1:8000/admin/default/edit/Contour/controllers/devices2.py>, 
> line 214, in <module>
>   File "/Volumes/BrandonsData/Google 
> Drive/web2py/web2py.app/Contents/Resources/gluon/globals.py", line 372, in 
> <lambda>
>   File "/Volumes/BrandonsData/Google 
> Drive/web2py/web2py.app/Contents/Resources/applications/Contour/controllers/devices2.py"
>  <http://127.0.0.1:8000/admin/default/edit/Contour/controllers/devices2.py>, 
> line 47, in list2
>   File "applications/Contour/modules/engine5.py", line 395, in show_settings
>   File "/Volumes/BrandonsData/Google 
> Drive/web2py/web2py.app/Contents/Resources/gluon/sqlhtml.py", line 2473, in 
> grid
>   File "/Volumes/BrandonsData/Google 
> Drive/web2py/web2py.app/Contents/Resources/gluon/dal.py", line 9921, in 
> formatter
>   File "/Volumes/BrandonsData/Google 
> Drive/web2py/web2py.app/Contents/Resources/gluon/validators.py", line 2681, 
> in formatter
>   File "/Volumes/BrandonsData/Google 
> Drive/web2py/web2py.app/Contents/Resources/gluon/validators.py", line 369, in 
> formatter
>   File "json/__init__.pyc", line 231, in dumps
>   File "json/encoder.pyc", line 201, in encode
>   File "json/encoder.pyc", line 264, in iterencode
>   File "json/encoder.pyc", line 178, in default
> TypeError: <gluon.html.XML object at 0x10fecc190> is not JSON serializable
>
>
>
> Where am I going wrong here?
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to