在Emacs中生成JSON请求 [英] Making JSON requests within Emacs

查看:202
本文介绍了在Emacs中生成JSON请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正处于撰写 Emacs主要模式的早期阶段,用于浏览和贡献网站在Stack Exchange网络上,与 dired list-packages 的工作方式大致相同,具有一些启发 magit 组织模式

I am in the early stages of writing an Emacs major mode for browsing and contributing to sites on the Stack Exchange network, in much the same way as dired and list-packages works, with a few inspirations from magit and org-mode.

问题是当然,我不知道我如何将Emacs与SE API(v2.1)连接在一起。我从来没有做过涉及Elisp网络连接的任何事情,虽然我对语言本身很满意(并且已经花了不止一个看看 package.el ) 。

The problem is, of course, I have no idea how I would interface Emacs with the SE API (v2.1) in the first place. I've never done anything that involves a network connection within Elisp, although I'm comfortable with the language itself (and have taken more than a few looks at package.el).

我从未使用过JSON,尽管我处于 W3C的教程

I've never worked with JSON, although I'm in the middle of W3C's tutorial on it.

一个简单的hello world就足够了,可能沿着

A simple 'hello world' would suffice, possibly along the lines of

(execute-json-query "/info")

W3C教程似乎也没有超出请求。我必须自己做研究。

我真的不知道我在做什么,

The W3C tutorial doesn't seem to go over requests, either. I'll have to do my own research on that.
I really don't have any idea what I'm doing; I've only just started feverishly working on this yesterday afternoon.

推荐答案

其他答案的问题是堆栈Exchange API是GZIP'd ,并且随Emacs一起发送的url.el不会自动解压缩。

The problem with other answers is that Stack Exchange API is GZIP'd and url.el shipped with Emacs does not automatically decompress it.

看看我的 request.el 图书馆,支持自动解压缩(说实话,我刚刚添加了支持)。以下是一个在stackoverflow中获取最有效问题的示例:

Take a look at my request.el library which supports automatic decompression (to be honest, I just added the support). Here is an example to fetch the most active question in stackoverflow:

(request
 "https://api.stackexchange.com/2.1/questions"
 :params '((order . "desc")
           (sort . "activity")
           (site . "stackoverflow"))
 :parser 'json-read
 :success (function*
           (lambda (&key data &allow-other-keys)
             (let* ((item (elt (assoc-default 'items data) 0))
                    (title (assoc-default 'title item))
                    (tags (assoc-default 'tags item)))
               (message "%s %S" title tags)))))

request.el是记录好的文档,附带可执行示例< a>并且是经过良好测试的

request.el is well documented, comes with executable examples and is well tested.

这篇关于在Emacs中生成JSON请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆