Tip to remove L from interger 750L when exporting json to view?

37 views
Skip to first unread message

António Ramos

unread,
Jun 25, 2019, 9:23:18 AM6/25/19
to web...@googlegroups.com
Hello i have a dict like
var spendData = [
{'exist': 7250L, 'lote': 'F0523E103S'}, 
{'exist': 23100L, 'lote': 'F0609F103S'}, ...]

when in the view i get an error 
Uncaught SyntaxError: Invalid or unexpected token

i guess its the "L" and the end of 7250
how can i eliminate it  before passing the dict to the view?

regards
António

Leonel Câmara

unread,
Jun 25, 2019, 10:36:01 AM6/25/19
to web2py-users
That just means it's a long (python 2 has integers and longs). How are you putting that dict in the view? I would just serialize it using json.

Val K

unread,
Jun 25, 2019, 10:42:23 AM6/25/19
to web2py-users
How do you convert dict to json? I believe that json.dumps or response.json produces json strings without L suffix

António Ramos

unread,
Jun 25, 2019, 11:18:14 AM6/25/19
to web...@googlegroups.com
That is where i tried first..

first my controller 
return response.json(myvar)
it returned the json to the view correctly.

Then i need to return a dict to use it in my view.

ret= response.json(myvar)
return dict(ret=ret)
then in the view i just had
{{extend 'layout.html'}}
{{=ret}}

It does not work.
All my html is not interpreted and is dumpled like bellow...
image.png




Em ter, 25 de jun de 2019 às 15:42, Val K <valq...@gmail.com> escreveu:
How do you convert dict to json? I believe that json.dumps or response.json produces json strings without L suffix

--
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 web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/cad32539-a4c4-4d49-a964-4243a008a534%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonel Câmara

unread,
Jun 25, 2019, 12:14:19 PM6/25/19
to web2py-users
Just return the dict as is on the controller and then in the view you can do something like:

{{from gluon import serializers}}
{{=XML(serializers.json(spendData ), sanitize=False)}}

Another alternative is to use the ASSIGNJS helper if you want this in a javascript variable:

António Ramos

unread,
Jun 25, 2019, 12:55:57 PM6/25/19
to web...@googlegroups.com
Better.
Thank you  all :)

--
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 web2py+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages