ClojureScript-Ajax-检索json

问题描述 投票:0回答:1

我有我的依赖性

(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并将其分解为idnamestarrating的一种方法吗?

我尝试过

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

希望我会得到一张名为电影的地图,但无济于事!

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

json ajax clojurescript
1个回答
0
投票

知道了,

我在GET通话中缺少:response-format :json:keywords? true

现在,看起来像这样:

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

并且全部有效。

© www.soinside.com 2019 - 2024. All rights reserved.