猿问

使用 Golang 从 DuckDuckGo 解码 JSON

我一直在使用DuckDuckGo的Go 库,除了一件事外,它一直运行良好。在“相关主题”部分。通常,它看起来像这样:


{

"RelatedTopics" : [

      {

         "Result" : "<a href=\"http://duckduckgo.com/Criticism_of_Google\">Criticism of Google</a> - Criticism of Google includes possible misuse and manipulation of search results, its use of others' intellectual property, concerns that its compilation of data may violate people's privacy, cen...",

         "Icon" : {

            "URL" : "",

            "Height" : "",

            "Width" : ""

         },

         "FirstURL" : "http://duckduckgo.com/Criticism_of_Google",

         "Text" : "Criticism of Google - Criticism of Google includes possible misuse and manipulation of search results, its use of others' intellectual property, concerns that its compilation of data may violate people's privacy, cen..."

      },

      {

         "Result" : "<a href=\"http://duckduckgo.com/PRISM_(surveillance_program)\">PRISM</a> - PRISM is a clandestine mass electronic surveillance data mining program known to have been operated by the United States National Security Agency (NSA) since 2007.",

         "Icon" : {

            "URL" : "",

            "Height" : "",

            "Width" : ""

         },

         "FirstURL" : "http://duckduckgo.com/PRISM_(surveillance_program)",

         "Text" : "PRISM - PRISM is a clandestine mass electronic surveillance data mining program known to have been operated by the United States National Security Agency (NSA) since 2007."

      },



但是,有时在“RealtedTopics”部分中,会出现一系列“Topics”,其中包含许多“Results”和该 Topic 的“Name”。


Cats萌萌
浏览 204回答 1
1回答

慕无忌1623718

主题似乎包含一个切片Topics []Topic:type Icon struct {&nbsp; URL string&nbsp; Height string&nbsp; Width string}type Topic struct {&nbsp; Result string&nbsp; Icon Icon&nbsp; FirstURL string&nbsp; Text string&nbsp; Topics []Topic `json:",omitempty"`}type RootObj struct {&nbsp;RelatedTopics []Topic}
随时随地看视频慕课网APP

相关分类

Go
我要回答