KRL:将字符串解析为 JSON
使用 http:get()
后,我从哈希中 pick
接收到一个字符串:
response = http:get(webservice_url, {"key1": value1, "key2": value2});
json_resp = response.pick("$..content");
但是,由于 json_resp
是一个字符串而不是一个实际的 JSON 对象,我无法运行这样的命令:
value = json_resp.pick("$..string");
有没有办法告诉 KRL 我想将 json_resp 解析为 JSON?也许是一个eval()
之类的东西?
After using http:get()
, I receive back a string from pick
ing the "content" from the hash:
response = http:get(webservice_url, {"key1": value1, "key2": value2});
json_resp = response.pick("$..content");
However, since json_resp
is a string and not an actual JSON object, I can't run a command like this:
value = json_resp.pick("$..string");
Is there a way to tell KRL that I want to parse json_resp
as JSON? An eval()
or something, perhaps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
decode()
运算符正是您想要的。它对 JSON 字符串进行操作,尝试将其转换为本机 KRL 对象。请注意,KRL 还具有在本机 KRL 上运行的encode()
对象并返回该对象的 JSON 字符串表示形式。The
decode()
operator does just what you want. It operates on a JSON string, attempting to convert it to a native KRL object. Note that KRL also hasencode()
which operates on a native KRL object and returns a JSON string representation of that object.