从 android 发送 JSON 数据到 compojure 服务器

发布于 2024-12-21 22:56:34 字数 1011 浏览 6 评论 0原文

我正在尝试将一些 json 数据从 Android 发送到 clojure/compojure 服务器

但是我似乎无法正确发送或接收数据,而且我不太确定问题是否出在 Android 或者 compojure 上。

这是java代码

String PATH = "http://localhost:8080/get_position";
DefaultHttpClient mClient = new DefaultHttpClient();

HttpGet httpget = new HttpGet(PATH);
HttpResponse response;
httpget.getParams().setParameter("measurements", measurements.toString());

response = mClient.execute(httpget);
HttpEntity entity = response.getEntity();

,其中measurements是JSON对象。

用于处理路由的主要 compojure 代码

(defroutes main-routes
   (POST "/get_position" {params :params}
      (emit-json (find-location (:results (read-json (:measurements params))))))
   (route/not-found "Page not found"))

请求被正确接收,但我收到一个错误,params 为 nil

java.lang.IllegalArgumentException: No implementation of method: :read-json-from of protocol: #'clojure.data.json/Read-JSON-From found for class: nil   

有没有人看到此代码有问题或知道执行此操作的正确方法?

I'm trying to send some json data from Android to a clojure/compojure server

However I can't seem to able to properly send or receive the data, and I'm not quite sure if the problem lies with Android or compojure.

Here is the java code

String PATH = "http://localhost:8080/get_position";
DefaultHttpClient mClient = new DefaultHttpClient();

HttpGet httpget = new HttpGet(PATH);
HttpResponse response;
httpget.getParams().setParameter("measurements", measurements.toString());

response = mClient.execute(httpget);
HttpEntity entity = response.getEntity();

Where mesurements is the JSON object.

And the main compojure code for handling the routing

(defroutes main-routes
   (POST "/get_position" {params :params}
      (emit-json (find-location (:results (read-json (:measurements params))))))
   (route/not-found "Page not found"))

The request is properly received, but I get an error that params is nil

java.lang.IllegalArgumentException: No implementation of method: :read-json-from of protocol: #'clojure.data.json/Read-JSON-From found for class: nil   

Does anyone see a problem with this code or knows the correct way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各空 2024-12-28 22:56:34

我相信参数映射以字符串作为键,而不是关键字。

The params map has strings as keys, I believe, not keywords.

野の 2024-12-28 22:56:34

我建议使用 ring-json-params

I recommend using ring-json-params.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文