0

HTTPoison用来获取 elixir 指南网站,然后对其进行解析Floki以构建 HTML 2 Jupyter Notebook 转换器(使用 Markdown 进行描述)。我必须输入`反引号。\u0060用于代码突出显示,到目前为止有效。我有一些地方使用字符串插值"#{Floki.text(childs_nodes)}"和其他地方Enum.join ""来处理和转换从 HTML 到 Markdown。

转换后的结果根据 jupyter notebook 格式存储在地图中。当我打电话时Poison.encode notebook,我得到一个错误,因为代码点已经消失了。我尝试了不同的东西,但还不知道问题出在哪里。

任何提示我在处理文本时做错了什么?这是一个例外:

** (Poison.EncodeError) unable to encode value: {:source, ["Elixir also    provides `Port`, `Reference` and `PID` as data types (usually used in process communication), and we will take a quick look at them when talking about processes. For now, let’s take a look at some of the basic operators that go with our basic types."]}
lib/poison/encoder.ex:377: Poison.Encoder.Any.encode/2
lib/poison/encoder.ex:255: anonymous fn/3 in Poison.Encoder.List.encode/3
lib/poison/encoder.ex:256: Poison.Encoder.List."-encode/3-lists^foldr/2-1-"/3
lib/poison/encoder.ex:256: Poison.Encoder.List.encode/3
lib/poison.ex:41: Poison.encode!/2
(guide2nb) lib/cli.ex:27: CLI.process/1
(elixir) lib/kernel/cli.ex:76: anonymous fn/3 in Kernel.CLI.exec_fun/2
4

1 回答 1

2

这里的问题是您正在尝试对 a 进行编码Tuple,而 Poison 仅适用于地图和列表。如果您尝试编码的值是 Map 而不是元组,它将完美地工作。Unicode 与此无关。

iex(1)> value = %{source: ["Elixir also    provides `Port`, `Reference` and `PID` as data types (usually used in process communication), and we will take a quick look at them when talking about processes. For now, let’s take a look at some of the basic operators that go with our basic types."]}
iex(2)> Poison.encode(value)
{:ok,
 "{\"source\":[\"Elixir also    provides `Port`, `Reference` and `PID` as data types (usually used in process communication), and we will take a quick look at them when talking about processes. For now, let’s take a look at some of the basic operators that go with our basic types.\"]}"}
于 2016-11-03T03:35:36.860 回答