Httpie: JSON 解析错误

创建于 2017-04-13  ·  7评论  ·  资料来源: httpie/httpie

嘿,

首先,httpie 是一款出色的软件。 我不记得我推荐了多少同事使用它。

我遇到了一个问题。 根据规范,提供 JSON 参数是通过:=操作符完成的。 但是使用这些参数启动 httpie 0.9.9:

http post localhost/example/ param1="a b c" param2=d jparam:='["test string"]'

导致有关无效 JSON 的消息。 但是["test string"]是有效的 JSON afaik。

http: error: "jparam:='[test string]'": Expecting value: line 1 column 1 (char 0)

也许任何人都可以对似乎有问题的地方发表一些看法?

最有用的评论

@poskadesign试试这个:

http post localhost/example/ param1="a b c" param2=d jparam:="[\"test string\"]"

我对 Windows 命令行不是很熟悉,但找到了类似的https://stackoverflow.com/questions/17205292/quotes-around-quotes-in-windows-command-line

所有7条评论

如果我错了,请纠正我,但 JSON 对象通常不是 {"key":"value"} 格式吗?

@poskadesign命令看起来不错,它在 Bash 中对我

$ http -v httpbin.org/post  param1="a b c" param2=d jparam:='["test string"]'
POST /post HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 61
Content-Type: application/json
Host: httpbin.org
User-Agent: HTTPie/0.9.9

{
    "jparam": [
        "test string"
    ],
    "param1": "a b c",
    "param2": "d"
}
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 568
Content-Type: application/json
Date: Sun, 14 May 2017 10:58:53 GMT
Server: meinheld/0.6.1
Via: 1.1 vegur
X-Powered-By: Flask
X-Processed-Time: 0.000903844833374

{
    "args": {},
    "data": "{\"param1\": \"a b c\", \"param2\": \"d\", \"jparam\": [\"test string\"]}",
    "files": {},
    "form": {},
    "headers": {
        "Accept": "application/json, */*",
        "Accept-Encoding": "gzip, deflate",
        "Connection": "close",
        "Content-Length": "61",
        "Content-Type": "application/json",
        "Host": "httpbin.org",
        "User-Agent": "HTTPie/0.9.9"
    },
    "json": {
        "jparam": [
            "test string"
        ],
        "param1": "a b c",
        "param2": "d"
    },
    "origin": "…",
    "url": "http://httpbin.org/post"
}

嗨,我是开源项目的新手。 我想在这个问题上工作。 你能给我提供更多信息吗?

@poskadesign 那是什么操作系统和外壳? 看起来您的 shell 使用了双引号以避免在空格上进行分词,但随后在参数中留下了单引号。

就是这样.. http POST https://httpbin.org/post wicked=witch casts:='["spells", "curses"]' --json

@sriyanfernando仍然不起作用(httpie 0.99,Windows 10x64,Python 3.61,标准 Windows 命令提示符):

C:\Users\Me>http post localhost:8000/mail/ recipients:='["[email protected]"]' --json
usage: http [--json] [--form] [--pretty {all,colors,format,none}]
            [--style STYLE] [--print WHAT] [--headers] [--body] [--verbose]
            [--all] [--history-print WHAT] [--stream] [--output FILE]
            [--download] [--continue]
            [--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
            [--auth USER[:PASS]] [--auth-type {basic,digest}]
            [--proxy PROTOCOL:PROXY_URL] [--follow]
            [--max-redirects MAX_REDIRECTS] [--timeout SECONDS]
            [--check-status] [--verify VERIFY]
            [--ssl {ssl2.3,ssl3,tls1,tls1.1,tls1.2}] [--cert CERT]
            [--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version]
            [--traceback] [--default-scheme DEFAULT_SCHEME] [--debug]
            [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]
http: error: "recipients:='[[email protected]]'": Expecting value: line 1 column 1 (char 0)

@poskadesign试试这个:

http post localhost/example/ param1="a b c" param2=d jparam:="[\"test string\"]"

我对 Windows 命令行不是很熟悉,但找到了类似的https://stackoverflow.com/questions/17205292/quotes-around-quotes-in-windows-command-line

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

rshurts picture rshurts  ·  5评论

jclem picture jclem  ·  6评论

loretoparisi picture loretoparisi  ·  6评论

rashthedude picture rashthedude  ·  3评论

a-x- picture a-x-  ·  7评论