json - Postgres : How to convert a json string to

Json 值可以由一个字符串值组成。例如:

postgres=# SELECT to_json('Some "text"'::TEXT);
     to_json
-----------------
 "Some \"text\""

如何将该字符串提取为 postgres 文本值?

::TEXT 不起作用。它返回带引号的 json,而不是原始字符串:

postgres=# SELECT to_json('Some "text"'::TEXT)::TEXT;
     to_json
-----------------
 "Some \"text\""

谢谢。

附:我正在使用 PostgreSQL 9.3

最佳答案

在 9.4.4 中使用 #>>运算符(operator)为我工作:

select to_json('test'::text) #>> '{}';

与表格列一起使用:

select jsoncol #>> '{}' from mytable;

关于json - Postgres : How to convert a json string to text?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27215216/

相关文章:

python - 如何在 Django 中不使用模板返回 JSON?

ios - 在 Swift 中将 JSON 字符串转换为 Object 的简单而干净的方法

javascript - 如何将 JSON 转换为 CSV 格式并存储在变量中

json - 将 Go map 转换为 json

javascript - 如何通过 Ajax 请求将 Select2 与 JSON 一起使用?

xml - json和xml有什么区别

javascript - JSON 安全最佳实践?

python - 如何以不同的顺序比较具有相同元素的两个 JSON 对象相等?

json - 任何用于在 Classic ASP 中解析 JSON 的好库?

c# - JavaScriptSerializer.Deserialize - 如何更改字段名称