简要说明
我将 bottle.py 用作简单的Web服务器,并且我正在渲染javascript,将其传递给python字典,然后在javascript文件中,我想向对象添加另一个字段,并使用结果发出post请求。
但是,当我记录数据类型时,datain返回字符串,因此我无法将新属性添加到对象中。likePost()
另外,我尝试没有并返回以下错误:JSON.Stringify()Unexpected token ' in JSON at position
法典
function commentPost(post){
var comment = prompt("Comment:", "Great post I like it")
data = JSON.parse(JSON.stringify(post))
console.log(typeof data) // RETURNS STRING
data.comment = comment // THIS DOESN'T WORK
fetch("/post", {
method: "POST",
body: JSON.stringify(data)
}).then(res => {
likePost(data)
});
}
控制台.log(帖子) 控制台.log(帖子类型)
{'hashtag': 'landscapephotography', 'shortcode': 'B_5b0IWqrRU', 'display_url': 'https://scontent-mad1-1.cdninstagram.com/v/t51.2885-15/e35/s1080x1080/95910887_233194497953707_7239044831960646903_n.jpg?_nc_ht=scontent-mad1-1.cdninstagram.com&_nc_cat=107&_nc_ohc=i179pDQmui0AX82O3nB&oh=676ca07cba3af57944abcba4d3a27ad2&oe=5EDE8D74', 'thumbnail_src': 'https://scontent-mad1-1.cdninstagram.com/v/t51.2885-15/sh0.08/e35/s640x640/95910887_233194497953707_7239044831960646903_n.jpg?_nc_ht=scontent-mad1-1.cdninstagram.com&_nc_cat=107&_nc_ohc=i179pDQmui0AX82O3nB&oh=1ff2ac0b031bcc7cbdbb64b2a661ea1b&oe=5EDF0745', 'is_video': False, 'comments_disabled': False, 'caption': 'Photo by Jelen Girona on May 07, 2020.', 'comments_count': 0, 'timestamp': 1588877630, 'owner': '15642627659', 'likes_count': 0}
string
qq_花开花谢_0
相关分类