无论如何在json django中编辑响应?我正在使用视图视图集
{
"title": "Cloister",
"number": 2,
"summary": "Erasmas describes several buildings of the Concent, namely the Scriptiorium...",
"page_count": 14
},
例如:首先我得到像这样的 json 返回:"标题":"回廊",我想在 get 字符串后添加一些东西,最终结果必须是:"title":"回廊+这里的东西"!
我的任务是获取产品名称,并检查名称是否>40个字符,然后只需40个字符并加上"..."40 个字符后
见下文:
jsonres={
"title": "Cloister",
"number": 2,
"summary": "Erasmas describes several buildings of the Concent, namely the Scriptiorium...",
"page_count": 14
}
title=jsonres.get("title")
jsonres["title"]=title + "somethinghere!" #to add something to title
if len(title) > 40:
jsonres["title"]=title.replace(title[40:],"...") # to truncate 40 + characters and replace