Answer the question
In order to leave comments, you need to log in
Generate Json object?
Need help with a seemingly simple yet complex issue. I create a json object like this. How to create it so that there is also an archive inside the key? I try the generation method but I get a string. Which json.dumps() does not accept.
pole = {
"recordsFiltered": 2,
"data": [
{
"history_money": "-11 часов",
"history_text": "НОМЕР: 79089688399 Абонет: Доступен"
},
{
"history_money": "+11 часов",
"history_text": "НОМЕР: 79189688399 Абонет: Доступен"
}
]
}
print(pole['data'][0]['history_money'])
import json
pol = {"history_money": "-11 часов", "history_text": "НОМЕР: 79089688399 Абонет: Доступен"}
rep = {"recordsFiltered":1,"data":"" + str(pol) + ""}
print(rep)
print(rep['data'][0]['history_money'])
{'recordsFiltered': 1, 'data': []}
Answer the question
In order to leave comments, you need to log in
pol = {
"history_money": "-11 часов",
"history_text": "НОМЕР: 79089688399 Абонет: Доступен"
}
rep = {
"recordsFiltered": 1,
}
rep['data'] = [pol]
print(rep)
print(rep['data'][0]['history_money'])
import json
print(json.dumps(rep, indent=4, ensure_ascii=False))
# {
# "recordsFiltered": 1,
# "data": [
# {
# "history_money": "-11 часов",
# "history_text": "НОМЕР: 79089688399 Абонет: Доступен"
# }
# ]
#}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question