- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 python-requests 来处理 elasticsearch 索引。特别是我没有从 requests.json() 得到我想要的东西(在标准库中包装 json.loads() 函数)。
我正在努力处理 json() 方法返回的结果。它似乎正在返回一个字符串列表。我想要一个可以循环访问每个成员属性的 dict 对象,即......
r = requests.get(url)
results = r.json() //same as results = json.loads(json string)
print(results)
for result in results:
print(result['source'])
这是我手动使用 curl 执行搜索时 Elasticsearch 返回的内容(这是 r.json() 调用的输入):
{"took":5,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":18,"max_score":1.0,"hits":[{"_index":"feed","_type":"article","_id":"Bq2_NxWIRZS5mfX_jxv5YQ","_score":1.0, "_so urce" : {"source": ["http://www.naturalnews.com/040631_farmed_salmon_GMO_sustainable_fishing.html"], "link": ["http://www.naturalnews.com/040631_farmed_salmon_GMO_sustainable_fishing.html"], "description ": ["<table><tr><td><img src=\"http://www.naturalnews.com/gallery/300X250/Food/Salmon-Raw.jpg\" /></td><td valign=\"top\">Equally as menacing as the potential release of genetically-modified (GM) salmon into the wild, factory fish farms are a modern scourge responsible for killing off droves of native fish species all around the world. And unless immediate action is taken to address this...</td></tr></t able>"], "title": ["Fish farming killing off native species; boycott farmed salmon before it's too late"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 193}},{"_index":"feed","_type": "article","_id":"jxfFD6V-Qwacc4KYNfChcg","_score":1.0, "_source" : {"source": ["http://www.naturalnews.com/040628_calf_exercises_soleus_stretch_lower_body_workouts.html"], "link": ["http://www.naturalnew s.com/040628_calf_exercises_soleus_stretch_lower_body_workouts.html"], "description": ["<table><tr><td><img src=\"http://www.naturalnews.com/gallery/300X250/Exercise/Running-Shoes-Fitness-Legs-Calves-Mus cles.jpg\" /></td><td valign=\"top\">Building killer calves is more complicated than people think. Most exercisers do a bunch of standing calf exercises like standing calf raises, sled hack calf raises, donkey raises, and calf presses to bulk up not realizing that their entire workout is only targeting...</td></tr></table>"], "title": ["Calf exercises: Sit down to build yourself up"], "published": ["Wed , 5 Jun 2013 00:00:00 CST"], "medoozie_score": 228}},{"_index":"feed","_type":"article","_id":"RBV1P_lXStKAHeaNi-q9Bg","_score":1.0, "_source" : {"source": ["http://www.naturalnews.com/040626_Hopewood_ch ildren_natural_living_organic_foods.html"], "link": ["http://www.naturalnews.com/040626_Hopewood_children_natural_living_organic_foods.html"], "description": ["<table><tr><td><img src=\"http://www.natura lnews.com/gallery/300X250/Children/Kids-Children-Play-Outside-Happy-Exercise.jpg\" /></td><td valign=\"top\">In 1942, the founder of the Natural Health Society of Australia, Leslie Owen Bailey, began a s ocial experiment: He chose to adopt 85 children whose parents were unable to provide for them. The children's residence became the sprawling Hopewood House in New South Wales...</td></tr></table>"], "tit le": ["Honoring nature: The lesson of the Hopewood children"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 187}},{"_index":"feed","_type":"article","_id":"uP6G2_leSl2-gUMyUie3eA","_s core":1.0, "_source" : {"source": ["http://www.naturalnews.com/040636_IRS_scandal_conservative_groups_Obama_Administration.html"], "link": ["http://www.naturalnews.com/040636_IRS_scandal_conservative_gro ups_Obama_Administration.html"], "description": ["<table><tr><td><img src=\"http://www.naturalnews.com/gallery/300X250/Money/IRS-Building-Revenue-Taxes-Money.jpg\" /></td><td valign=\"top\">Officials wit h the Internal Revenue Service (IRS) have admitted that the agency inappropriately targeted conservative groups seeking legal tax-exemption status in the years and months leading up to the 2012 election. Those same officials have apologized for the targeting...</td></tr></table>"], "title": ["Claim: IRS still targeting conservative groups, even after promising the intimidation already stopped"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 342}},{"_index":"feed","_type":"article","_id":"yhcqfmKQRwSVhR1vUIy0vg","_score":1.0, "_source" : {"source": ["http://www.natu ralnews.com/040633_Bug_Eating_Festival_insects_survival_foods.html"], "link": ["http://www.naturalnews.com/040633_Bug_Eating_Festival_insects_survival_foods.html"], "description": ["<table><tr><td><img s rc=\"http://www.naturalnews.com/gallery/300X250/Women/Party-Girls-Fun.jpg\" /></td><td valign=\"top\">Are people in Austin so hungry they are eating bugs? \"Well, it does help if you c ome to the party having skipped lunch,\" says Marjory Wildcraft, the host and creator 6th Annual Bug Eating Festival which will be held on Saturday June 29, 2013 at Zilker Park in Austin...</td></tr></ta ble>"], "title": ["6th Annual Bug Eating Festival"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 252}},{"_index":"feed","_type":"article","_id":"Grh9KUDVQvSs7oRUjzOG9A","_score":1.0, "_source" : {"source": ["http://www.naturalnews.com/040630_egg_whites_blood_pressure_peptides.html"], "link": ["http://www.naturalnews.com/040630_egg_whites_blood_pressure_peptides.html"], "description" : ["<table><tr><td><img src=\"http://www.naturalnews.com/gallery/300X250/Food/Brown-Eggs-On-White.jpg\" /></td><td valign=\"top\">Considering that eggs contain all the nutrients needed to develop healthy chicks, it is unsurprising that studies into their numerous health benefits for humans abound. Eating more eggs has, for instance, been repeatedly linked to reduced LDL cholesterol, a lowered risk...</t d></tr></table>"], "title": ["Peptide found in egg whites can lower blood pressure, say researchers"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 262}},{"_index":"feed","_type":"art icle","_id":"6OfIM7G9Rke-TD3N6bI4Ow","_score":1.0, "_source" : {"source": ["http://www.naturalnews.com/040629_obesity_vitamin_D_deficiency_exercise.html"], "link": ["http://www.naturalnews.com/040629_obe sity_vitamin_D_deficiency_exercise.html"], "description": ["<table><tr><td><img src=\"http://www.naturalnews.com/gallery/300X250/Men/Big-Fat-Hairy-Obese-Belly.jpg\" /></td><td valign=\"top\">Confirming w hat health professionals have long suspected, a new study published in the journal PLOS Medicine provides some of the strongest evidence yet that obesity is indeed a cause of vitamin D deficiency. &# 10; The large study was a collaborative effort between U.S...</td></tr></table>"], "title": ["Obesity causes vitamin-D deficiency: Research"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "med oozie_score": 313}},{"_index":"feed","_type":"article","_id":"osvu1IlkSwa9yL566YoQuQ","_score":1.0, "_source" : {"source": ["http://www.naturalnews.com/040627_Judge_Napolitano_Eric_Holder_freedom_of_the_ press.html"], "link": ["http://www.naturalnews.com/040627_Judge_Napolitano_Eric_Holder_freedom_of_the_press.html"], "description": ["<table><tr><td><img src=\"http://www.naturalnews.com/gallery/300X250/C oncepts/Extra-Liar-Newspaper-Headline.jpg\" /></td><td valign=\"top\">Terrorism, and the threat of new attacks, dominated U.S. domestic policy and national security strategy throughout the Bush Administr ation, but my, how times have changed: Despite the recent terrorist bombings of the Boston Marathon April 19, President Barack Obama appears...</td></tr></table>"], "title": ["Judge Napolitano: Obama mor e threatened by journalism than terrorism"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 34}},{"_index":"feed","_type":"article","_id":"0XfVTXImTWGwQ1Ko13Q9hg","_score":1.0, "_source " : {"source": ["http://www.naturalnews.com/040637_mental_illness_depression_women.html"], "link": ["http://www.naturalnews.com/040637_mental_illness_depression_women.html"], "description": ["<table><tr> <td><img src=\"http://www.naturalnews.com/gallery/300X250/Cancer/Poor-Women-Breast-Cancer.jpg\" /></td><td valign=\"top\">For reasons that are still largely unclear, women are much more likely than men t o develop some form of mental illness during their lives, whether it be depression, schizophrenia, or simple anxiety, according to a new study. Based on an analysis of 12 large-scale epidemiological...</ td></tr></table>"], "title": ["Women are 40 percent more likely to develop mental illness than men, study concludes"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 434}},{"_index":"fe ed","_type":"article","_id":"8L699AbUTtmlrnlSJlmzhw","_score":1.0, "_source" : {"source": ["http://www.naturalnews.com/040624_cancer_industry_documentary_lies.html"], "link": ["http://www.naturalnews.com /040624_cancer_industry_documentary_lies.html"], "description": ["<table><tr><td><img src=\"http://www.naturalnews.com/gallery/300x250/Programs/Cut-Poison-Burn.jpg\" /></td><td valign=\"top\">The stunnin g, jaw-dropping and tearfully devastating true story of the conventional cancer industry is unleashed in a new documentary called \"Cut, Poison, Burn.\" While celebrities like Michael Douglas are grabbin g headlines by promoting the dangerous myths and false...</td></tr></table>"], "title": ["Profiteering cancer industry ripped wide open by explosive documentary 'Cut, Poison, Burn' - watch preview here"] , "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 187}}]}}
这是我将 request.json() 返回的结果写入 txt 文件时得到的结果:
'{"source": ["http://www.naturalnews.com/040640_front_groups_food_industry_processed.html"], "link": ["http://www.naturalnews.com/040640_front_groups_food_industry_processed.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Logos/Pepsi-Logo.jpg\\" /></td><td valign=\\"top\\">Some say it\'s the best public relations that money can buy, because when you can\'t refute the truth about an issue, the next-best thing to do is stack the deck in your favor. The third edition of a report released last month by the International Food Information Council...</td></tr></table>"], "title": ["Food industry front groups exposed in new report: Monsanto, Coke, Pepsi and more"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 350}'
'{"source": ["http://www.naturalnews.com/040639_Obamacare_insurance_premiums_individual_mandate.html"], "link": ["http://www.naturalnews.com/040639_Obamacare_insurance_premiums_individual_mandate.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300x250/celebrities/Barack-Obama-Portrait.jpg\\" /></td><td valign=\\"top\\">The scramble is on to bring the logistical framework for Obamacare into full fruition before its inaugural arrival in 2014. But as legislators and program architects dig down into the nitty-gritty of what the \\"tax\\" will actually entail in practicality, it is becoming...</td></tr></table>"], "title": ["Obamacare will collapse under the weight of rising premiums"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 121}'
'{"source": ["http://www.naturalnews.com/040638_Garcinia_cambogia_weight_loss_obestity.html"], "link": ["http://www.naturalnews.com/040638_Garcinia_cambogia_weight_loss_obestity.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Men/Belly-Fat.jpg\\" /></td><td valign=\\"top\\">With celeb Dr. Oz advocating its use, Garcinia Cambogia (also known as Malabar tamarind, gambooge and brindleberry), has gained notoriety as a fast-acting and cheap fat buster that both suppresses appetite and prevents fat from being made. For generations, this fruit...</td></tr></table>"], "title": ["Does Garcinia cambogia extract really help with weight loss?"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 120}'
'{"source": ["http://www.naturalnews.com/040637_mental_illness_depression_women.html"], "link": ["http://www.naturalnews.com/040637_mental_illness_depression_women.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Cancer/Poor-Women-Breast-Cancer.jpg\\" /></td><td valign=\\"top\\">For reasons that are still largely unclear, women are much more likely than men to develop some form of mental illness during their lives, whether it be depression, schizophrenia, or simple anxiety, according to a new study. Based on an analysis of 12 large-scale epidemiological...</td></tr></table>"], "title": ["Women are 40 percent more likely to develop mental illness than men, study concludes"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 468}'
'{"source": ["http://www.naturalnews.com/040636_IRS_scandal_conservative_groups_Obama_Administration.html"], "link": ["http://www.naturalnews.com/040636_IRS_scandal_conservative_groups_Obama_Administration.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Money/IRS-Building-Revenue-Taxes-Money.jpg\\" /></td><td valign=\\"top\\">Officials with the Internal Revenue Service (IRS) have admitted that the agency inappropriately targeted conservative groups seeking legal tax-exemption status in the years and months leading up to the 2012 election. Those same officials have apologized for the targeting...</td></tr></table>"], "title": ["Claim: IRS still targeting conservative groups, even after promising the intimidation already stopped"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 12}'
'{"source": ["http://www.naturalnews.com/040635_cooling_foods_summer_eating_whole.html"], "link": ["http://www.naturalnews.com/040635_cooling_foods_summer_eating_whole.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Women/Woman-Summersault-Grass-Fitness-Play.jpg\\" /></td><td valign=\\"top\\">As we enter into the dog days of summer, it\'s easy to keep cool with specific foods and herbs under our belt. Using the wisdom of Traditional Chinese Medicine (TCM), we can remain balanced, calm and energetic as the mercury rises. Particular suggestions border on simple...</td></tr></table>"], "title": ["Stay cool this summer with natural medicine and herbal remedies"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 495}'
'{"source": ["http://www.naturalnews.com/040634_mental_health_President_Obama_Big_Pharma.html"], "link": ["http://www.naturalnews.com/040634_mental_health_President_Obama_Big_Pharma.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Concepts/Man-Hat-Brain-Concept.jpg\\" /></td><td valign=\\"top\\">President Obama gave psychiatrists and pharmaceutical companies the keys to the kingdom during his keynote speech at the White House Conference on Mental Health this week. Celebrated as a hero to the shamed and downtrodden, Obama played the part well as he subtly...</td></tr></table>"], "title": ["Obama keynote speech deals death blow to mental health, delivers millions into the hands of big pharma"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 280}'
'{"source": ["http://www.naturalnews.com/040633_Bug_Eating_Festival_insects_survival_foods.html"], "link": ["http://www.naturalnews.com/040633_Bug_Eating_Festival_insects_survival_foods.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Women/Party-Girls-Fun.jpg\\" /></td><td valign=\\"top\\">Are people in Austin so hungry they are eating bugs? \\"Well, it does help if you come to the party having skipped lunch,\\" says Marjory Wildcraft, the host and creator 6th Annual Bug Eating Festival which will be held on Saturday June 29, 2013 at Zilker Park in Austin...</td></tr></table>"], "title": ["6th Annual Bug Eating Festival"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 191}'
'{"source": ["http://www.naturalnews.com/040632_C-sections_obesity_childbirth.html"], "link": ["http://www.naturalnews.com/040632_C-sections_obesity_childbirth.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Medical/Woman-Giving-Birth-Delivering-Baby-Nurses-Doctors-Hospital.jpg\\" /></td><td valign=\\"top\\">New research out of the U.K. sheds light on yet another possible cause of widespread childhood obesity. Based on an analysis involving more than 10,000 British babies, roughly 9 percent of whom were born via C-section, researchers found that babies delivered the alternate...</td></tr></table>"], "title": ["C-sections lead to obese kids, study finds"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 64}'
'{"source": ["http://www.naturalnews.com/040631_farmed_salmon_GMO_sustainable_fishing.html"], "link": ["http://www.naturalnews.com/040631_farmed_salmon_GMO_sustainable_fishing.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Food/Salmon-Raw.jpg\\" /></td><td valign=\\"top\\">Equally as menacing as the potential release of genetically-modified (GM) salmon into the wild, factory fish farms are a modern scourge responsible for killing off droves of native fish species all around the world. And unless immediate action is taken to address this...</td></tr></table>"], "title": ["Fish farming killing off native species; boycott farmed salmon before it\'s too late"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 281}'
'{"source": ["http://www.naturalnews.com/040630_egg_whites_blood_pressure_peptides.html"], "link": ["http://www.naturalnews.com/040630_egg_whites_blood_pressure_peptides.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Food/Brown-Eggs-On-White.jpg\\" /></td><td valign=\\"top\\">Considering that eggs contain all the nutrients needed to develop healthy chicks, it is unsurprising that studies into their numerous health benefits for humans abound. Eating more eggs has, for instance, been repeatedly linked to reduced LDL cholesterol, a lowered risk...</td></tr></table>"], "title": ["Peptide found in egg whites can lower blood pressure, say researchers"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 118}'
'{"source": ["http://www.naturalnews.com/040629_obesity_vitamin_D_deficiency_exercise.html"], "link": ["http://www.naturalnews.com/040629_obesity_vitamin_D_deficiency_exercise.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Men/Big-Fat-Hairy-Obese-Belly.jpg\\" /></td><td valign=\\"top\\">Confirming what health professionals have long suspected, a new study published in the journal PLOS Medicine provides some of the strongest evidence yet that obesity is indeed a cause of vitamin D deficiency. The large study was a collaborative effort between U.S...</td></tr></table>"], "title": ["Obesity causes vitamin-D deficiency: Research"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 395}'
'{"source": ["http://www.naturalnews.com/040628_calf_exercises_soleus_stretch_lower_body_workouts.html"], "link": ["http://www.naturalnews.com/040628_calf_exercises_soleus_stretch_lower_body_workouts.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Exercise/Running-Shoes-Fitness-Legs-Calves-Muscles.jpg\\" /></td><td valign=\\"top\\">Building killer calves is more complicated than people think. Most exercisers do a bunch of standing calf exercises like standing calf raises, sled hack calf raises, donkey raises, and calf presses to bulk up not realizing that their entire workout is only targeting...</td></tr></table>"], "title": ["Calf exercises: Sit down to build yourself up"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 469}'
'{"source": ["http://www.naturalnews.com/040627_Judge_Napolitano_Eric_Holder_freedom_of_the_press.html"], "link": ["http://www.naturalnews.com/040627_Judge_Napolitano_Eric_Holder_freedom_of_the_press.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Concepts/Extra-Liar-Newspaper-Headline.jpg\\" /></td><td valign=\\"top\\">Terrorism, and the threat of new attacks, dominated U.S. domestic policy and national security strategy throughout the Bush Administration, but my, how times have changed: Despite the recent terrorist bombings of the Boston Marathon April 19, President Barack Obama appears...</td></tr></table>"], "title": ["Judge Napolitano: Obama more threatened by journalism than terrorism"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 96}'
'{"source": ["http://www.naturalnews.com/040626_Hopewood_children_natural_living_organic_foods.html"], "link": ["http://www.naturalnews.com/040626_Hopewood_children_natural_living_organic_foods.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Children/Kids-Children-Play-Outside-Happy-Exercise.jpg\\" /></td><td valign=\\"top\\">In 1942, the founder of the Natural Health Society of Australia, Leslie Owen Bailey, began a social experiment: He chose to adopt 85 children whose parents were unable to provide for them. The children\'s residence became the sprawling Hopewood House in New South Wales...</td></tr></table>"], "title": ["Honoring nature: The lesson of the Hopewood children"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 445}'
'{"source": ["http://www.naturalnews.com/040625_lawsuit_Monsanto_genetic_pollution.html"], "link": ["http://www.naturalnews.com/040625_lawsuit_Monsanto_genetic_pollution.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Farming/Man-Farmer-Wheat-Crop-Field-Clouds-Sky.jpg\\" /></td><td valign=\\"top\\">The next wave of farmer backlash against Monsanto has just been unleashed by Ernest Barnes, a wheat farmer in Morton County, Kansas. He filed suit this week in the U.S. District Court in Wichita, Kansas, alleging that Monsanto\'s genetic pollution has financially damaged...</td></tr></table>"], "title": ["It\'s on! Farmers begin suing Monsanto over genetic pollution of wheat crops"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 311}'
'{"source": ["http://www.naturalnews.com/040624_cancer_industry_documentary_lies.html"], "link": ["http://www.naturalnews.com/040624_cancer_industry_documentary_lies.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300x250/Programs/Cut-Poison-Burn.jpg\\" /></td><td valign=\\"top\\">The stunning, jaw-dropping and tearfully devastating true story of the conventional cancer industry is unleashed in a new documentary called \\"Cut, Poison, Burn.\\" While celebrities like Michael Douglas are grabbing headlines by promoting the dangerous myths and false...</td></tr></table>"], "title": ["Profiteering cancer industry ripped wide open by explosive documentary \'Cut, Poison, Burn\' - watch preview here"], "published": ["Wed, 5 Jun 2013 00:00:00 CST"], "medoozie_score": 216}'
'{"source": ["http://www.naturalnews.com/040623_Morninglane_Dairy_Vernon_Hershberger_food_freedom.html"], "link": ["http://www.naturalnews.com/040623_Morninglane_Dairy_Vernon_Hershberger_food_freedom.html"], "description": ["<table><tr><td><img src=\\"http://www.naturalnews.com/gallery/300X250/Farming/Farmer-Crops.jpg\\" /></td><td valign=\\"top\\">There is a war being waged against real food - no, not the heavily-processed, chemical-laden garbage that fills the aisles of most major supermarkets today, but actual wholesome food grown on clean, family-scale farms across the U.S. And the upcoming documentary Let...</td></tr></table>"], "title": ["\'Let Them Eat Grass\' documentary to expose massive government tyranny against small-scale farmers producing real food"], "published": ["Tue, 4 Jun 2013 00:00:00 CST"], "medoozie_score": 211}'
{u'hits': {u'hits': [{u'_score': 0.32461247, u'_type': u'article', u'_id': u'yBqM5NSoTDCAeXo2YRO1hQ', u'_source': {u'description': [u'<table><tr><td><img src="http://www.naturalnews.com/gallery/300X250/Concepts/Man-Hat-Brain-Concept.jpg" /></td><td valign="top">President Obama gave psychiatrists and pharmaceutical companies the keys to the kingdom during his keynote speech at the White House Conference on Mental Health this week. Celebrated as a hero to the shamed and downtrodden, Obama played the part well as he subtly...</td></tr></table>'], u'title': [u'Obama keynote speech deals death blow to mental health, delivers millions into the hands of big pharma'], u'source': [u'http://www.naturalnews.com/040634_mental_health_President_Obama_Big_Pharma.html'], u'link': [u'http://www.naturalnews.com/040634_mental_health_President_Obama_Big_Pharma.html'], u'medoozie_score': 93, u'published': [u'Wed, 5 Jun 2013 00:00:00 CST']}, u'_index': u'feed'}, {u'_score': 0.16524655, u'_type': u'article', u'_id': u'Grh9KUDVQvSs7oRUjzOG9A', u'_source': {u'description': [u'<table><tr><td><img src="http://www.naturalnews.com/gallery/300X250/Food/Brown-Eggs-On-White.jpg" /></td><td valign="top">Considering that eggs contain all the nutrients needed to develop healthy chicks, it is unsurprising that studies into their numerous health benefits for humans abound. Eating more eggs has, for instance, been repeatedly linked to reduced LDL cholesterol, a lowered risk...</td></tr></table>'], u'title': [u'Peptide found in egg whites can lower blood pressure, say researchers'], u'source': [u'http://www.naturalnews.com/040630_egg_whites_blood_pressure_peptides.html'], u'link': [u'http://www.naturalnews.com/040630_egg_whites_blood_pressure_peptides.html'], u'medoozie_score': 262, u'published': [u'Wed, 5 Jun 2013 00:00:00 CST']}, u'_index': u'feed'}, {u'_score': 0.16524655, u'_type': u'article', u'_id': u'6OfIM7G9Rke-TD3N6bI4Ow', u'_source': {u'description': [u'<table><tr><td><img src="http://www.naturalnews.com/gallery/300X250/Men/Big-Fat-Hairy-Obese-Belly.jpg" /></td><td valign="top">Confirming what health professionals have long suspected, a new study published in the journal PLOS Medicine provides some of the strongest evidence yet that obesity is indeed a cause of vitamin D deficiency. The large study was a collaborative effort between U.S...</td></tr></table>'], u'title': [u'Obesity causes vitamin-D deficiency: Research'], u'source': [u'http://www.naturalnews.com/040629_obesity_vitamin_D_deficiency_exercise.html'], u'link': [u'http://www.naturalnews.com/040629_obesity_vitamin_D_deficiency_exercise.html'], u'medoozie_score': 313, u'published': [u'Wed, 5 Jun 2013 00:00:00 CST']}, u'_index': u'feed'}, {u'_score': 0.15372275, u'_type': u'article', u'_id': u'RBV1P_lXStKAHeaNi-q9Bg', u'_source': {u'description': [u'<table><tr><td><img src="http://www.naturalnews.com/gallery/300X250/Children/Kids-Children-Play-Outside-Happy-Exercise.jpg" /></td><td valign="top">In 1942, the founder of the Natural Health Society of Australia, Leslie Owen Bailey, began a social experiment: He chose to adopt 85 children whose parents were unable to provide for them. The children\'s residence became the sprawling Hopewood House in New South Wales...</td></tr></table>'], u'title': [u'Honoring nature: The lesson of the Hopewood children'], u'source': [u'http://www.naturalnews.com/040626_Hopewood_children_natural_living_organic_foods.html'], u'link': [u'http://www.naturalnews.com/040626_Hopewood_children_natural_living_organic_foods.html'], u'medoozie_score': 187, u'published': [u'Wed, 5 Jun 2013 00:00:00 CST']}, u'_index': u'feed'}], u'total': 4, u'max_score': 0.32461247}, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}, u'took': 66, u'timed_out': False}
如何让 json.loads(json-string) 返回字典而不是字符串或字符串列表?如果这不可能,那么将列表中的每个字符串转换为字典的好方法是什么?
事实证明 r.json() 函数从未被破坏。我只是不知道如何遍历结果。
下面是我如何修改我的代码以便我可以遍历它...
r = requests.get('http://localhost:9200/feed/_search?q=' + query)
results = r.json()
for result in results['hits']['hits']:
print(result['_source']['title'])
这是我正在解码的 json 的较小示例...
最佳答案
事实证明 r.json() 函数从未被破坏。我只是不知道如何遍历结果。
下面是我如何修改我的代码以便我可以遍历它...
r = requests.get('http://localhost:9200/feed/_search?q=' + query)
results = r.json()
for result in results['hits']['hits']:
print(result['_source']['title'])
这是我正在解码的 json 的较小示例...
关于python - 如何让 json.loads(json-string) 返回字典而不是字符串或字符串列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16941601/
我正在处理一组标记为 160 个组的 173k 点。我想通过合并最接近的(到 9 或 10 个组)来减少组/集群的数量。我搜索过 sklearn 或类似的库,但没有成功。 我猜它只是通过 knn 聚类
我有一个扁平数字列表,这些数字逻辑上以 3 为一组,其中每个三元组是 (number, __ignored, flag[0 or 1]),例如: [7,56,1, 8,0,0, 2,0,0, 6,1,
我正在使用 pipenv 来管理我的包。我想编写一个 python 脚本来调用另一个使用不同虚拟环境(VE)的 python 脚本。 如何运行使用 VE1 的 python 脚本 1 并调用另一个 p
假设我有一个文件 script.py 位于 path = "foo/bar/script.py"。我正在寻找一种在 Python 中通过函数 execute_script() 从我的主要 Python
这听起来像是谜语或笑话,但实际上我还没有找到这个问题的答案。 问题到底是什么? 我想运行 2 个脚本。在第一个脚本中,我调用另一个脚本,但我希望它们继续并行,而不是在两个单独的线程中。主要是我不希望第
我有一个带有 python 2.5.5 的软件。我想发送一个命令,该命令将在 python 2.7.5 中启动一个脚本,然后继续执行该脚本。 我试过用 #!python2.7.5 和http://re
我在 python 命令行(使用 python 2.7)中,并尝试运行 Python 脚本。我的操作系统是 Windows 7。我已将我的目录设置为包含我所有脚本的文件夹,使用: os.chdir("
剧透:部分解决(见最后)。 以下是使用 Python 嵌入的代码示例: #include int main(int argc, char** argv) { Py_SetPythonHome
假设我有以下列表,对应于及时的股票价格: prices = [1, 3, 7, 10, 9, 8, 5, 3, 6, 8, 12, 9, 6, 10, 13, 8, 4, 11] 我想确定以下总体上最
所以我试图在选择某个单选按钮时更改此框架的背景。 我的框架位于一个类中,并且单选按钮的功能位于该类之外。 (这样我就可以在所有其他框架上调用它们。) 问题是每当我选择单选按钮时都会出现以下错误: co
我正在尝试将字符串与 python 中的正则表达式进行比较,如下所示, #!/usr/bin/env python3 import re str1 = "Expecting property name
考虑以下原型(prototype) Boost.Python 模块,该模块从单独的 C++ 头文件中引入类“D”。 /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c)
如何编写一个程序来“识别函数调用的行号?” python 检查模块提供了定位行号的选项,但是, def di(): return inspect.currentframe().f_back.f_l
我已经使用 macports 安装了 Python 2.7,并且由于我的 $PATH 变量,这就是我输入 $ python 时得到的变量。然而,virtualenv 默认使用 Python 2.6,除
我只想问如何加快 python 上的 re.search 速度。 我有一个很长的字符串行,长度为 176861(即带有一些符号的字母数字字符),我使用此函数测试了该行以进行研究: def getExe
list1= [u'%app%%General%%Council%', u'%people%', u'%people%%Regional%%Council%%Mandate%', u'%ppp%%Ge
这个问题在这里已经有了答案: Is it Pythonic to use list comprehensions for just side effects? (7 个答案) 关闭 4 个月前。 告
我想用 Python 将两个列表组合成一个列表,方法如下: a = [1,1,1,2,2,2,3,3,3,3] b= ["Sun", "is", "bright", "June","and" ,"Ju
我正在运行带有最新 Boost 发行版 (1.55.0) 的 Mac OS X 10.8.4 (Darwin 12.4.0)。我正在按照说明 here构建包含在我的发行版中的教程 Boost-Pyth
学习 Python,我正在尝试制作一个没有任何第 3 方库的网络抓取工具,这样过程对我来说并没有简化,而且我知道我在做什么。我浏览了一些在线资源,但所有这些都让我对某些事情感到困惑。 html 看起来
我是一名优秀的程序员,十分优秀!