【问题标题】:Returning json from the kdb webserver从 kdb 网络服务器返回 json
【发布时间】:2016-07-15 05:22:35
【问题描述】:

来自 qprompt,例如我们可以跑了,

x: select from table
.j.j x

如何以 json 格式返回向 kdb 网络服务器发出的 http url 获取请求(例如 host:port/?select from table)的表格结果,而不是纯文本?

我可以获取文本形式的表格结果并解析 html 响应,但更愿意以 json 格式从 http 服务器本身获取结果

谢谢

【问题讨论】:

  • localhost:5555/?.j.j 从标签中选择”不起作用?
  • 我尝试的第一件事,但对我不起作用。它应该吗?我也在 3.2 之前的旧版本 kdb 上,所以我手动加载了 json.k
  • 如果 .j.j select from table 在 q 控制台上工作,那么它也应该通过 http 工作。在浏览器中打开 localhost:5555/?.j.j select from tab 会发生什么?
  • 无论如何它在 3.4 上对我有用。很确定它也适用于 >=3.2
  • 抱歉回复晚了。我犯了一个错误,上面的建议最终对我有用。非常感谢您的帮助!

标签: kdb


【解决方案1】:

要将数据作为 JSON 对象获取,您必须在 KDB 响应的响应标头中设置 Content-Type:application/json

为此,您必须提供 .z.ph 函数自定义实现并将下面的行附加到您的响应数据的说明中。

  "HTTP/1.x 200 OK\r\nContent- Type:application/json\r\n\r\n"

示例实现

 .z.ph:{:"HTTP/1.x 200 OK\r\nContent- Type:application/json\r\n\r\n", .j.j table_data }

在 z.ph 函数中你会得到一个字典作为输入

x[0]: query from browser
x[1]: request header 

现在您必须编写自定义实现来处理您的 x[0] 查询

 If query through Http client was http://localhost:2001/?select from t then
 x[0] will be "?select%20from%20t" where t is kdb table 
 you have to decode x[0] string to remove white space and other character in string.
    value (decoded string);

【讨论】:

    猜你喜欢
    • 2012-01-02
    • 1970-01-01
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    相关资源
    最近更新 更多