【问题标题】:Send JSON data to compojure server from android从 android 发送 JSON 数据到 compojure 服务器
【发布时间】:2011-12-18 23:30:28
【问题描述】:

我正在尝试将一些 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();

其中 mesurements 是 JSON 对象。

以及处理路由的主要组合代码

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

请求被正确接收,但我得到一个错误,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   

是否有人发现此代码存在问题或知道执行此操作的正确方法?

【问题讨论】:

    标签: android json http clojure compojure


    【解决方案1】:

    我相信,params 映射将字符串作为键,而不是关键字。

    【讨论】:

      【解决方案2】:

      我推荐使用ring-json-params

      【讨论】:

        猜你喜欢
        • 2011-09-25
        • 1970-01-01
        • 1970-01-01
        • 2012-01-09
        • 2016-06-12
        • 1970-01-01
        • 1970-01-01
        • 2012-07-19
        • 2015-08-21
        相关资源
        最近更新 更多