-2

How i can parse it?

    check = request.POST.getlist('check')

    print(check)

    [u'["1","2"]']

send ajax JSON data to server

2 Answers2

0

It sounds like you want to decode it from JSON sent from the browser. You can do encode or decode like this:

import json

# to encode a list to json
json.dumps(yourlist)

# to decode it from json
json.loads(yourjson)

Reference: The Python Docs

Cody Parker
  • 1,111
  • 6
  • 10
-3

In your list, you have received a string. To parse through this look-alike list, you will have to go through the individual characters. Here is an example:

list = [u'["1","2"]']

for i in range(len(list[0])):
    print list[0][i]

Output:

[
"
1
"
,
"
2
"
]

You can parse through this by starting at list[0][2] and incrementing by 4.

Vaibhav Bajaj
  • 1,934
  • 16
  • 29
  • 1
    Why go to the work of iterating over the list by index? A much more Pythonic way would be to simply iterate over the list by value: `for el in list[0]`. Also, one should note that it is general not a good idea to overwrite builtin names. – Christian Dean Feb 13 '17 at 19:50