I got a string in this form
payload = ["Text 1", "Text 2"]
I want to use Text 2
as an object. How can I return it?
UPDATE
I’m making a function which returns a generic template Facebook API.
The first payload
works well, but I want to return a string
and a object
in the second payload
( result )
button = [
{
"type": "postback",
"title": "Buy item",
"payload": "Buy this item: " + (product['id'])
},
{
"type": "postback",
"title": "Add to wishlist",
"payload": result
}
]
My second payload should look like this:
payload = {
'Order_item',
product['title']
}
Because I got this error [buttons][1][payload] must be a UTF-8 encoded string
so I did convert it and it returns a STRING in this form ["Order_item", "Ledverlichting Fiets Blauw"]
Because I want that when a Facebook user clicks on a postback ( Add to wishlist ), the product['title']
value will be save in Django database. And product['title']
is the Text 2
in the question above.
4
Answers
You need to split the string then trim and keep splitting/trimming to get all parts that you want to have in list
then you have list of string that you can iterate, get n-th item and so on
you can try:
assuming that you want a string object, you can get the specific index in the array(first spot = 0, second spot = 1, etc).
you can save the string object contained in the array like this:
and than you can return the s object.
I had a string that was in strictly list format and simply passing it through eval() worked.