【问题标题】:No JSON object could be decoded - tastypie - curl无法解码任何 JSON 对象 - 美味派 - 卷曲
【发布时间】:2012-07-09 07:21:03
【问题描述】:

在我到达帖子部分之前,我一直在逐字关注美味派教程: http://django-tastypie.readthedocs.org/en/latest/interacting.html#creating-a-new-resource-post

当我运行此命令时,我不断收到以下错误: No JSON object could be decoded

我检查并确定我正在逐字遵循文档。

感谢您的帮助

【问题讨论】:

    标签: python django json curl tastypie


    【解决方案1】:

    原来是带有 cURL 的 windows 东西。

    1. JSON 数据应使用双引号 ("") 而非单引号引起来。
    2. json 数据包中的所有双引号必须用反斜杠 (\) 转义

    例如:所以,这个:

    curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"body": "This will prbbly be my lst post.", "pub_date": "2011-05-22T00:46:38", "slug": "another-post", "title": "Another Post", "user": "/api/v1/user/1/"}' http://localhost:8000/api/v1/entry/

    应该是:

    curl --dump-header - -H "Content-Type: application/json" -X POST --data "{\"body\": \"This will prbbly be my lst post.\", \"pub_date\": \"2011-05-22T00:46:38\", \"slug\": \"another-post\", \"title\": \"Another Post\", \"user\": \"/api/v1/user/1/\"}" http://localhost:8000/api/v1/entry/

    【讨论】:

    • 感谢您用您的答案更新此内容,我遇到了完全相同的问题!
    • 这种情况其实可以用单引号,虽然不知道你原来的命令是怎么写的
    猜你喜欢
    • 1970-01-01
    • 2014-11-27
    • 2013-01-19
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多