我一直在使用用于DuckDuckGo的Go库,除了一件事外,它一直运行得很好。在"RelatedTopics“部分。通常,它看起来是这样的:
{
"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."
},
{
"Result" : "<a href=\"http://duckduckgo.com/Google_Panda\">Google Panda</a> - Google Panda is a change to Google's search results ranking algorithm that was first released in February 2011.",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Google_Panda",
"Text" : "Google Panda - Google Panda is a change to Google's search results ranking algorithm that was first released in February 2011."
},
{
"Result" : "<a href=\"http://duckduckgo.com/Google_Penguin\">Google Penguin</a> - Google Penguin is a code name for a Google algorithm update that was first announced on April 24, 2012.",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Google_Penguin",
"Text" : "Google Penguin - Google Penguin is a code name for a Google algorithm update that was first announced on April 24, 2012."
},
{
"Result" : "<a href=\"http://duckduckgo.com/Google_search_features\">Google search features</a> - The Google search features include more than 40 options or keywords to modify the type of search.",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Google_search_features",
"Text" : "Google search features - The Google search features include more than 40 options or keywords to modify the type of search."
},
{
"Result" : "<a href=\"http://duckduckgo.com/Google_Searchology\">Google Searchology</a> - Google Searchology 2009 witnessed several novel changes in the Google search options.",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Google_Searchology",
"Text" : "Google Searchology - Google Searchology 2009 witnessed several novel changes in the Google search options."
},
{
"Result" : "<a href=\"http://duckduckgo.com/c/Multilingual_websites\">Multilingual websites</a>",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/c/Multilingual_websites",
"Text" : "Multilingual websites"
},
{
"Result" : "<a href=\"http://duckduckgo.com/c/Google_services\">Google services</a>",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/c/Google_services",
"Text" : "Google services"
},
{
"Result" : "<a href=\"http://duckduckgo.com/c/Internet_search_engines\">Internet search engines</a>",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/c/Internet_search_engines",
"Text" : "Internet search engines"
},
{
"Result" : "<a href=\"http://duckduckgo.com/c/American_websites\">American websites</a>",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/c/American_websites",
"Text" : "American websites"
}
]
}然而,有时在"RealtedTopics“一节中,会出现一系列”主题“,其中包含许多”结果“,并出现了该主题的”名称“。
如果这没什么意义的话我很抱歉。这方面的一个很好的例子是当你搜索博士。
{
"RelatedTopics" : [
{
"Result" : "<a href=\"http://duckduckgo.com/Doctor_Who\">Doctor Who</a> is the title of a long-running British science fiction series.",
"Icon" : {
"URL" : "https://i.duckduckgo.com/i/www.bbc.co.uk.ico",
"Height" : 16,
"Width" : 16
},
"FirstURL" : "http://duckduckgo.com/Doctor_Who",
"Text" : "Doctor Who is the title of a long-running British science fiction series."
},
{
"Result" : "<a href=\"http://duckduckgo.com/Doctor_(Doctor_Who)\">Doctor (Doctor Who)</a>, the main character in the British television series",
"Icon" : {
"URL" : "https://i.duckduckgo.com/i/e32c2703.jpg",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Doctor_(Doctor_Who)",
"Text" : "Doctor (Doctor Who), the main character in the British television series"
},
{
"Result" : "<a href=\"http://duckduckgo.com/Doctor_Who_theme_music\">Doctor Who theme music</a>, the theme music created for the television series, and has changed many times over the 50 years it has been running.",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Doctor_Who_theme_music",
"Text" : "Doctor Who theme music, the theme music created for the television series, and has changed many times over the 50 years it has been running."
},
{
"Topics" : [
{
"Result" : "<a href=\"http://duckduckgo.com/Doctor_Who_(film)\">Doctor Who (film)</a>, the television movie starring Paul McGann, based on the television series",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Doctor_Who_(film)",
"Text" : "Doctor Who (film), the television movie starring Paul McGann, based on the television series"
},
{
"Result" : "<a href=\"http://duckduckgo.com/Dr._Who_(Dalek_films)\">Dr. Who (Dalek films)</a>, the human character played by Peter Cushing in two films based on the television series",
"Icon" : {
"URL" : "https://i.duckduckgo.com/i/9f10647e.jpg",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Dr._Who_(Dalek_films)",
"Text" : "Dr. Who (Dalek films), the human character played by Peter Cushing in two films based on the television series"
},
{
"Result" : "<a href=\"http://duckduckgo.com/Doctor_Who_(pinball)\">Doctor Who (pinball)</a>, pinball machine based on the television series",
"Icon" : {
"URL" : "https://i.duckduckgo.com/i/eee6de34.jpg",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Doctor_Who_(pinball)",
"Text" : "Doctor Who (pinball), pinball machine based on the television series"
},
{
"Result" : "<a href=\"http://duckduckgo.com/Doctor_Who_theme_music\">Doctor Who theme music</a>, the theme music created for the television series, and has changed many times over the 50 years it has been running.",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Doctor_Who_theme_music",
"Text" : "Doctor Who theme music, the theme music created for the television series, and has changed many times over the 50 years it has been running."
},
{
"Result" : "<a href=\"http://duckduckgo.com/Doctor_Who_(CSI)\">\"Doctor Who\" (CSI)</a>, the 22nd episode of the 10th season of CSI: Crime Scene Investigation",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Doctor_Who_(CSI)",
"Text" : "\"Doctor Who\" (CSI), the 22nd episode of the 10th season of CSI: Crime Scene Investigation"
}
],
"Name" : "In media and entertainment"
},
{
"Topics" : [
{
"Result" : "<a href=\"http://duckduckgo.com/Neoregelia_'Dr._Who'\">Neoregelia 'Dr. Who'</a>, a hybrid cultivar of the genus Neoregelia in the Bromeliad family",
"Icon" : {
"URL" : "",
"Height" : "",
"Width" : ""
},
"FirstURL" : "http://duckduckgo.com/Neoregelia_'Dr._Who'",
"Text" : "Neoregelia 'Dr. Who', a hybrid cultivar of the genus Neoregelia in the Bromeliad family"
}
],
"Name" : "In other uses"
}
]
}如何扩展库以便访问这些“主题”?我想不出用json.Unmarshal (库所用的方法)来完成它的方法。
致以敬意,
生姜比尔
发布于 2013-11-23 09:39:28
似乎主题中包含了一个片段Topics []Topic。
type Icon struct {
URL string
Height string
Width string
}
type Topic struct {
Result string
Icon Icon
FirstURL string
Text string
Topics []Topic `json:",omitempty"`
}
type RootObj struct {
RelatedTopics []Topic
}https://stackoverflow.com/questions/20156775
复制相似问题