2016-11-08 16 views
0

これは私が現在持っているものです。私の結果をどのようにトラバースできますか?

{:total-pages 1, :total-results 1, :items [{:item-atributes {:title Tolkien Calendar 2017, :product-group Book, :manufacturer Harper Voyager, :author J. R. 
R. Tolkien}, :SalesRank 12016, :item-links [{:description Technical Details, :url https://www.amazon.com/Tolkien-Calendar-2017-J-R/dp/tech-data/0062566938 
%3FSubscriptionId%3DAKIAI6FVBZ4SCQ3VMGCQ%26tag%3D215401-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0062566938} {:description Ad 
d To Baby Registry, :url https://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3D0062566938%26SubscriptionId%3DAKIAI6FVBZ4SCQ3VMGCQ%26tag%3D215401 
-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0062566938} {:description Add To Wedding Registry, :url https://www.amazon.com/gp/r 
egistry/wedding/add-item.html%3Fasin.0%3D0062566938%26SubscriptionId%3DAKIAI6FVBZ4SCQ3VMGCQ%26tag%3D215401-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D3 
86001%26creativeASIN%3D0062566938} {:description Add To Wishlist, :url https://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3D0062566938%26Su 
bscriptionId%3DAKIAI6FVBZ4SCQ3VMGCQ%26tag%3D215401-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0062566938} {:description Tell A 
Friend, :url https://www.amazon.com/gp/pdp/taf/0062566938%3FSubscriptionId%3DAKIAI6FVBZ4SCQ3VMGCQ%26tag%3D215401-20%26linkCode%3Dxm2%26camp%3D2025%26creati 
ve%3D386001%26creativeASIN%3D0062566938} {:description All Customer Reviews, :url https://www.amazon.com/review/product/0062566938%3FSubscriptionId%3DAKIAI 
6FVBZ4SCQ3VMGCQ%26tag%3D215401-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0062566938} {:description All Offers, :url https://ww 
w.amazon.com/gp/offer-listing/0062566938%3FSubscriptionId%3DAKIAI6FVBZ4SCQ3VMGCQ%26tag%3D215401-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26cre 
ativeASIN%3D0062566938}], :detail-page-url https://www.amazon.com/Tolkien-Calendar-2017-J-R/dp/0062566938%3FSubscriptionId%3DAKIAI6FVBZ4SCQ3VMGCQ%26tag%3D2 
15401-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0062566938, :asin 0062566938}]} 

私は結果からこれを持って、それを横断したかったです。

答えて

0

いいえ、XMLではありません。 get-inを使用すると、ネストされた構造をトラバースできます。

+0

私がやってみました(印刷を(取得-中(amazon_search I)[:アイテム:アイテムatributes:タイトル])))しかし、それは戻っています私には何もない。 amazon_searchは、ネストされた構造体を取得する関数です。 – lalakers4life

+0

:itemsは配列です。あなたはそんなに慣れることができますか? – jmargolisvt

+0

私はそれを得た。ありがとう! – lalakers4life

-1

@jmargolistvtによると、xmlではなく、Clojureデータ構造(ネストされたマップ&配列)があります。

printlnなどの代わりにprnを使用して印刷してください。「Harper Voyager」のような文字列に二重引用符を使用することが重要です。得

(ns clj.core 
    (:require 
    [tupelo.core :as t] 
    [clojure.pprint :as pp] 
    ) 
    (:gen-class)) 
(t/refer-tupelo) 

(def data 
    {:total-pages 1, :total-results 1, :items 
    [ {:item-atributes 
      {:title "Tolkien Calendar 2017", :product-group "Book", 
      :manufacturer "Harper Voyager" 
      :author "J. R. R. Tolkien" }, :SalesRank 12016, :item-links [{:description "Technical Details" } ] 
    } ] }) 


(pp/pprint data) 

(defn -main [& args] 
) 

~/clj > lein run  
{:total-pages 1, 
:total-results 1, 
:items 
[{:item-atributes 
    {:title "Tolkien Calendar 2017", 
    :product-group "Book", 
    :manufacturer "Harper Voyager", 
    :author "J. R. R. Tolkien"}, 
    :SalesRank 12016, 
    :item-links [{:description "Technical Details"}]}]} 

をこの時点では、あなたが取得する

(newline) 
(doseq [item (data :items) ] 
    (newline) 
    (pp/pprint item) 
    (newline) 
    (spyx (item :SalesRank)) 
    (spyx (get-in item [:item-atributes :title]))) 

を追加することができます。

は、私がデータを少し単純化し、これを持って

{:item-atributes 
{:title "Tolkien Calendar 2017", 
    :product-group "Book", 
    :manufacturer "Harper Voyager", 
    :author "J. R. R. Tolkien"}, 
:SalesRank 12016, 
:item-links [{:description "Technical Details"}]} 

(item :SalesRank) => 12016 
(get-in item [:item-atributes :title]) => "Tolkien Calendar 2017" 

あなたproject.cljこれは(spyx ...)パートの仕事にするために含まれている必要があります

:dependencies [ 
    [tupelo "0.9.9"] ... 
+0

私は@ jmargolistvtの方法を使ってタイトルとセールスランクを抽出しました。私は約10冊の本を持っています、そして、私はタイトルを取得しています、それぞれからsalesrank。 salesrankに基づいて書籍を並べ替え、テーブル形式できれいに印刷するにはどうすればよいですか? – lalakers4life

+0

私は今このフォーマットにしています。(println(get-in(amazon_search isbn)[:items 0:item-atributes:title])) \t \t 0:SalesRank])) – lalakers4life

関連する問題