json转换为xml文件

    科技2022-07-12  134

    json转换为xml文件

    XML的问题 (The Problem With XML)

    When it comes to APIs, XML is a well-known feed format that has been around for a while and is still used to this day. However, as summarized by Tamlyn Rhodes:

    当涉及到API时,XML是一种众所周知的提要格式,已经存在了一段时间,并且一直沿用至今。 但是,正如Tamlyn Rhodes总结的那样:

    “Unfortunately, XML exists. For whatever reason, somebody once thought it was a good idea and now we’re stuck with it. Since most modern applications and APIs use JSON instead, it’s often necessary to convert XML into JSON…”

    “不幸的是,XML存在。 无论出于什么原因,有人曾经认为这是一个好主意,现在我们被它坚持了下来。 由于大多数现代应用程序和API都改用JSON,因此通常需要将XML转换为JSON…”

    As such, I was having an issue with one platform when I was trying to power one of my web apps with an XML API. When I initialized the call, the platform would not pick up on the XML attributes values (such as systemCode="us-tv"). Here’s an example snippet of metadata for an episode:

    因此,当我尝试使用XML API支持我的一个Web应用程序时,我在一个平台上遇到了问题。 当我初始化调用时,平台将不会接收XML属性值(例如systemCode="us-tv" )。 这是一个情节的元数据片段示例:

    <item contentType="tv_episode" contentId="df9c946a-e891-11ea-adc1-0242ac120002"> <pubDate>2020-08-27T11:39:57-05:00</pubDate> <title locale="en-US">Episode Title</title> <description locale="en-US">Lorem ipsum...</description> <rating systemCode="us-tv">TV-14</rating> <artwork url="https://example.com/image.jpg" type="tile_artwork" locales="en-US" /></item>

    While there is plenty of XML to JSON converters available, they only give you a snapshot of the data that you copy and paste. But what if you have a feed that is constantly updating with new metadata or has a change in the template’s structure?

    尽管有大量的XML到JSON转换器可用 ,但它们仅为您提供了复制和粘贴数据的快照。 但是,如果您的供稿不断使用新的元数据进行更新,或者模板的结构发生了变化,该怎么办?

    解决方案:转换器API (The Solution: A Converter API)

    As a solution, I developed an API that converters a live XML to JSON. As a result, the platform I was having issues with can now parse those attribute values in the new format:

    作为解决方案,我开发了一个API,该API将实时 XML转换为JSON 。 结果,我遇到问题的平台现在可以解析新格式的那些属性值:

    "item": [ { "@contentType": "tv_episode", "@contentId": "df9c946a-e891-11ea-adc1-0242ac120002", "pubDate": "2020-03-26T11:39:57-05:00", "title": { "@locale": "en-US", "#text": "Episode Title" }, "description": { "@locale": "en-US", "#text": "Lorem ipsum..." }, "rating": { "@systemCode": "us-tv", "#text": "TV-14" }, "artwork": { "@url": "https://example.com/image.jpg", "@type": "tile_artwork", "@locales": "en-US" } }]

    Using the API is simple, just paste the XML URL in the parameter:

    使用该API很简单,只需将XML URL粘贴到参数中:

    https://api.factmaven.com/xml-to-json?xml=https://example.com/feed.xml

    My code is open-source and available on GitHub for those that want to host the API on their own. Found issues with it or ways to improve it? Don’t hesitate to reach out to me.

    我的代码是开源的,并在GitHub上提供给那些希望自己托管API的人。 发现问题或改进方法? 不要犹豫与我联系 。

    翻译自: https://levelup.gitconnected.com/how-to-convert-xml-to-json-without-rebuilding-your-feed-b09734329bc9

    json转换为xml文件

    相关资源:微信小程序源码-合集6.rar
    Processed: 0.014, SQL: 8