【问题标题】:ClojureScript - Ajax - Retrieving jsonClojureScript - Ajax - 检索 json
【发布时间】:2019-11-27 00:10:52
【问题描述】:

我有我的依赖

(ns test.core
    (:require [reagent.core :as reagent :refer [atom]]
              [ajax.core :refer [GET]]))

然后我有我的处理程序来处理对我的 ajax 调用的响应


(defn handle-response [response]
    (println (type response))
    (println film))

我调用的数据是 JSON,在浏览器中看起来像这样:

{"id":3,"name":"Sicario","star":"Emily Blunt","rating":5}

当我运行上面的 Clojure 时,我看到了:

cljs.core/PersistentArrayMap core.cljs:192:23
{id 3, name Sicario, star Emily Blunt, rating 5}

它们是我从 PersistArrayMap 中解构为id、name、star 和rating 的一种方式吗?

我试过了

(let [film (js->clj (.parse js/JSON response) :keywordize-keys true)]
   ...)

希望我能得到一张名为film的地图,但没有用!

我想也许我可以使用(get-in),但也无法获得正确的语法。 谢谢,

【问题讨论】:

    标签: json ajax clojurescript


    【解决方案1】:

    知道了,

    我的 GET 调用中缺少 :response-format :json 和 :keywords? true

    现在,它看起来像这样:

    (GET (str "https://localhost:5001/api/films/" film-name)
             {:response-format :json
              :keywords? true
    

    一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-15
      • 2015-10-20
      相关资源
      最近更新 更多