首页 \ 问答 \ 我想从一个给定的网址获取JSON数据而那个JSON数据我必须转换成XML形式(I want to fetch json data from a given url And that json data i have to convert into xml form)

我想从一个给定的网址获取JSON数据而那个JSON数据我必须转换成XML形式(I want to fetch json data from a given url And that json data i have to convert into xml form)

我想从给定的URL获取JSON数据

http://www.deanclatworthy.com/imdb/?=The+Green+Mile

并将JSON数据转换为XML。 我用urllibjson将JSON对象转换成python字典。

这是我的代码:

import json

json_string = '{"imdbid":"tt0120689","imdburl":"http:\/\/www.imdb.com\/title\/tt0120689\/","genres":"Crime,Drama,Fantasy,Mystery","languages":"English ,French","country":"USA","votes":"281023","stv":0,"series":0,"rating":"8.4","title":"The Green Mile","year":"1999","usascreens":2875,"ukscreens":340}'

new_python_object = json.loads(json_string)
print(json_string)
print()
print (new_python_object)

结果是:

{"imdbid":"tt0120689","imdburl":"http:\/\/www.imdb.com\/title\/tt0120689\/","genres":"Crime,Drama,Fantasy,Mystery","languages":"English ,French","country":"USA","votes":"281023","stv":0,"series":0,"rating":"8.4","title":"The Green Mile","year":"1999","usascreens":2875,"ukscreens":340}

{'ukscreens': 340, 'rating': '8.4', 'genres': 'Crime,Drama,Fantasy,Mystery', 'title': 'The Green Mile', 'series': 0, 'imdbid': 'tt0120689', 'year': '1999', 'votes': '281023', 'languages': 'English ,French', 'stv': 0, 'country': 'USA', 'usascreens': 2875, 'imdburl': 'http://www.imdb.com/title/tt0120689/'}

I want to fetch JSON data from a given url

http://www.deanclatworthy.com/imdb/?=The+Green+Mile

and convert the JSON data into XML. I have used urllib and json to convert JSON objects into python dictionary.

Here is my code:

import json

json_string = '{"imdbid":"tt0120689","imdburl":"http:\/\/www.imdb.com\/title\/tt0120689\/","genres":"Crime,Drama,Fantasy,Mystery","languages":"English ,French","country":"USA","votes":"281023","stv":0,"series":0,"rating":"8.4","title":"The Green Mile","year":"1999","usascreens":2875,"ukscreens":340}'

new_python_object = json.loads(json_string)
print(json_string)
print()
print (new_python_object)

And the result:

{"imdbid":"tt0120689","imdburl":"http:\/\/www.imdb.com\/title\/tt0120689\/","genres":"Crime,Drama,Fantasy,Mystery","languages":"English ,French","country":"USA","votes":"281023","stv":0,"series":0,"rating":"8.4","title":"The Green Mile","year":"1999","usascreens":2875,"ukscreens":340}

{'ukscreens': 340, 'rating': '8.4', 'genres': 'Crime,Drama,Fantasy,Mystery', 'title': 'The Green Mile', 'series': 0, 'imdbid': 'tt0120689', 'year': '1999', 'votes': '281023', 'languages': 'English ,French', 'stv': 0, 'country': 'USA', 'usascreens': 2875, 'imdburl': 'http://www.imdb.com/title/tt0120689/'}

原文:https://stackoverflow.com/questions/12627630
更新时间:2021-04-10 09:04

最满意答案

不,目前没有办法从索引中删除所有文档。 正如你怀疑删除并重新创建索引是要走的路。 对于非常小的索引,您可以考虑单独删除文档,但鉴于通常应用程序已创建索引的代码,删除/重新创建是最快捷的路径。


No, currently there's no way to delete all the documents from an index. As you suspected deleting and re-creating the index is the way to go. For really small indexes you could consider deleting documents individually but given that often apps have code for index creation already, delete/recreate is the quickest path.

相关问答

更多
  • 尝试运行: http://localhost:9200/_cat/indices?v 并检查索引是否确实被删除。 如果它不在列表中,那么您无法重新索引数据 - 删除索引意味着删除相应的文件/目录。 将来,请使用Aliases作为索引 ,以便在旧索引和新索引之间轻松切换,保持重新索引数据的可能性,或使用Snapshot模块为索引创建快照。 Try to run: http://localhost:9200/_cat/indices?v and check if the index was indeed r ...
  • 不,目前没有办法从索引中删除所有文档。 正如你怀疑删除并重新创建索引是要走的路。 对于非常小的索引,您可以考虑单独删除文档,但鉴于通常应用程序已创建索引的代码,删除/重新创建是最快捷的路径。 No, currently there's no way to delete all the documents from an index. As you suspected deleting and re-creating the index is the way to go. For really small i ...
  • 你可以检查一个被删除的文件是MultiFields类,如: Bits liveDocs = MultiFields.getLiveDocs(reader); if (!liveDocs.get(docID)) ... 因此,将其应用到您的代码中,可能是这样的: int maxdoc = reader.maxDoc(); Bits liveDocs = MultiFields.getLiveDocs(reader); for (int i = 0; i < maxdoc; i++) { if (!l ...
  • 你需要重新索引,基本上底层的lucene索引段是不可变的。 如果您有新的ES版本,此API将为您提供帮助: https : //www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html否则您必须使用搜索和滚动或仅重新获取数据原始来源 You need to reindex, basically underlying lucene index segment is immutable. If you have fresh ...
  • 您必须优化索引 。 请注意,优化是广泛的,您可能不应该每天做更多。 以下是有关优化的更多信息: http://www.lucidimagination.com/search/document/CDRG_ch06_6.3.1.3 http://wiki.apache.org/solr/SolrPerformanceFactors#Optimization_Considerations You have to optimize your index. Note that an optimize is expan ...
  • 删除只会将文档标记为已删除 - 它们仍然存在于索引中。 由于删除它们需要重写索引文件,因此在发出优化命令之前不会执行实际的删除操作。 还有一个选项可以在发出提交时expungeDeletes ,但据我所知,最好在正常工作时间以外发布优化。 如果您每晚删除文档,可以在删除后进行优化,或者甚至更频繁地进行优化,例如每隔两天或第三天。 优化需要与索引占用相同数量的空闲磁盘空间(因为最坏的情况是整个索引被重新写入)。 Deletions will only mark documents as deleted - t ...
  • 搜索YYYYMMdd *应该可以正常工作,因为当前日期存储为文本字符串。 获得结果后,您可以使用IndexReader.delete删除您不感兴趣的文档。在我看来,这是实现这一目标的最佳方法。 Searching for YYYYMMdd* should work as currently dates are stored as text strings. Once you have the results, you could use IndexReader.delete to remove the do ...
  • 这也让我感到惊讶,但似乎是正常行为。 “已删除”文档不再可搜索,因为它们的字段都为空,因此它们不会导致任何问题。 我遇到的问题是,如果搜索“-zomgwtfbbq”之类的东西,它们可以被返回,因为它们不包含术语“zomgwtfbbq”。 它也令人困惑,因为它使您的仪表板显示一个计数(“可搜索”文档),但如果您运行测试搜索-zomgwtfbbq(我一直用作“获取所有文档”的代理),您会得到一个不同的数。 我花了一段时间才弄清楚原因。 尽管他们所说的将版本设置为max uint32“永久删除”文档,它仍然会存在 ...
  • 给你一个卷曲的镜头,过去对我有用: curl http://localhost:8080/solr/update/?commit=true -H "Content-Type: text/xml" --data-binary '*:*'; 希望能帮助到你。 I found out that the issue was in my schema.xml I rewrote it and now works like a charm!
  • 您可以使用delete-by-query插件来实现这一目标。 您需要在所有节点上安装它 sudo bin/plugin install delete-by-query 然后,您可以将此依赖项添加到您的pom.xml org.elasticsearch.plugin delete-by-query 2.2.0

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)