我已經做this幾天,而我在這個問題:每當我試着編碼地圖(第一個元素)「之前,語法錯誤」,而URI.encode_query(形式)
映射到查詢字符串,我得到的錯誤「之前,語法錯誤:chat_id」
form = %{
"chat_id" => 237799109,
"text" => "OMG a message"
}
{status, body} = URI.encode_query(form)
#=> (SyntaxError) lib/elixir.ex:20: syntax error before: chat_id
但據我所知,這是地圖的語法,是不是?如看到here,其中呈現此示例:
iex> hd = %{"foo" => 1, "bar" => 2}
iex> URI.encode_query(hd)
"bar=2&foo=1
這裏發生了什麼?
完整的錯誤消息:
== Compilation error on file lib/elixir.ex ==
** (SyntaxError) lib/elixir.ex:20: syntax error before: chat_id
(elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.Paral
lelCompiler.spawn_compilers/1
那麼,它在IEx工作...........我不知道錯誤在哪裏然後。 – Besto
在鏈接到的文件中,在defix中不允許使用「def req」後面的空格(但錯誤消息與您在此處發佈的內容不同)。刪除空間後,文件編譯(有一些警告,但沒有錯誤)。 – Dogbert
呃,我刪除了這個空間,仍然得到了同樣的錯誤,「語法錯誤之前:chat_id」,並且還警告「一個表達式總是需要在 - >」右側編輯:也許它是我的靈藥版本?它是1.4.0,最新版本只是1.4.2 – Besto