问题标签 [xml-to-json]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
44 浏览

java - XSLT 3.0 - 无法在 XSLT 3.0 xml-to-json() 中获取对象数组

我正在尝试使用 XSLT 3.0 将给定的 json 数据从一种形式转换为另一种形式。我正在使用 XSLT 3.0 提供的 json-to-xml 和 xml-to-json 函数将数据从 .to json 转换为/从 xml 。

我有以下 json 数据。

我正在尝试使用 XSLT 3.0 将其转换为以下形式

我在 XSLT 以下。

但它只生产一个对象

谁能指出我需要进行更改的地方?

0 投票
1 回答
453 浏览

json - Azure APIM - XML 到 JSON 的转换

我试图弄清楚如何在 Azure APIM 策略编辑器中正确使用 XML 到 JSON 的转换。我见过几十个例子,其中所有的都是这样的:

但是,我无法在我的政策中找到合适的位置来放置代码以使其达到我的预期。这是我的出站策略,我希望在其中使用它:

如您所见,我尝试将转换线放在出站策略的最后,但它没有达到我的预期;我仍然返回了一个 xml 文档。

在了解如何修改我的政策以发挥作用的任何帮助都会很棒。

0 投票
0 回答
113 浏览

php - 如何在php中使用cdata将xml文件转换为json格式?

我正在尝试将我的 xml 文件(大文件)转换为 php 中的 json 格式。问题是 json 格式的 cdata 丢失。

这是我的代码,

XML 代码:

输出:

但实际输出应该是,

如您所见,“通道”属性包含的数据非常少。并且通过实际输出,您可以看到它包含更多数据。由于它是一个大文件,我插入了一小部分输出。我希望这么多的输出就足够了。如果您想了解更多详细信息,请在评论中提及。如果可能的话,我会插入它。

0 投票
1 回答
57 浏览

json - 从json文件中获取数据?

我正在使用将 XML 文件转换为 JSON 文件jsonDecode(jsonEncode(file))。问题是当我尝试从带有索引号的 JSON 文件中获取数据时。它只打印一个字母。我在下面插入了代码。看看我的代码有没有问题。如果我尝试使用字符串获取数据,则会显示错误。

我的文件很大。所以,我只插入一小部分输出。

我已经尝试过 xml2json 包并且得到了输出。

但是在没有任何包的 dart 中,我们可以将 XML 文件转换为带有import 'dart:convert';. 通过文档,我了解到它仅适用于小文件。如果它也适用于大文件,我想知道这段代码中的问题和解决方案。

这就是我在下面的代码中尝试的。

这是我的代码,

当我打印$jsonData这是输出时,

当我尝试从中打印一些数据时jsonData,这是我得到的输出,

代码:

输出:

代码:

输出:

代码:

输出:

据我了解,似乎 json 文件中的每个字母都单独保存在jsonData变量中。

0 投票
1 回答
52 浏览

json - Groovy 将 XML 转换为 JSON 数组

这是我的 XML

尝试将其转换为以下 JSON

我正在尝试使用以下代码,但它没有产生预期的结果:

0 投票
1 回答
23 浏览

java - JSON 到 JSON 的转换:可能的方法

有时需要执行从一种结构到另一种结构的相同格式的转换。现在在开始实施之前,首先需要理论基础。因此我的问题是 JSON 到 JSON 有哪些可能的转换方法?

0 投票
1 回答
71 浏览

java - 将 XML 转换为 JSON,同时保留 html 标签

根据下面的代码片段,我有 XML 文档需要使用 org.json 转换为 JSON。但是这种方法的问题是它不会在原始 XML 中保留 HTML 标签,例如将 XML 文本 <abstract>the max power density was 582.4 mW/m<sup>2</sup>. After temperature decreasing</abstract>映射到

"abstract":"the max power density was 582.4 mW/m. After temperature decreasing". 知道如何保留 HTML 标签吗?

0 投票
0 回答
25 浏览

flutter - 如何在 Flutter 中访问 xml2json 数据结构

我从 Flutter 中的 URL 检索 XML 数据并用于xml2json转换数据,但我似乎无法将其分离。

我从 XML 中得到以下数据结构:

如何将此信息分解为变量或数据集并分别打印结果,主要TitleArtistLength

0 投票
2 回答
45 浏览

python - 如何将 http get 响应从 html 转换为 json 格式(来自 kaggle.com)

我尝试下面的代码从 kaggle.com 获得 http 响应。Kaggle 响应为 html 格式,我想将其转换为 json 格式以便于进一步处理。

输出:

上面的代码对下面的所有方法都是通用的。

尝试1:

错误:

尝试2:

错误:

尝试 3:

错误:

参考: xml.parsers.expat.ExpatError: not well-formed (invalid token)

上述每一次尝试都以错误告终。请帮助我完成这项任务。

下面是我得到的 html 响应,

0 投票
0 回答
23 浏览

json - 将 xml 转换为 json,要求用特殊字符 [ 替换复杂元素

我需要使用 xslt 低于输出,其中结果标记表示输出中的数组。{使用 xslt 忽略元数据}

输入

<container_trip><results><__metadata><id>http://hxaix48.hq.auspost.com.au:8001/sap/opu/odata/SAP/ZGW_CONTAINER_TRIP_EVENT_SRV/container_tripSet('338760110225')</id><uri>http://hxaix48.hq.auspost.com.au:8001/sap/opu/odata/SAP/ZGW_CONTAINER_TRIP_EVENT_SRV/container_tripSet('338760110225')</uri><type>ZGW_CONTAINER_TRIP_EVENT_SRV.container_trip</type></__metadata><originator><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.event_originator</type></__metadata><person><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.Person</type></__metadata></person><system><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.System</type></__metadata></system></originator><container><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.Container</type></__metadata><product_group><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.Product_group</type></__metadata></product_group></container><audit><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.Audit</type></__metadata><em_last_event_guid>00000000-0000-0000-0000-000000000000</em_last_event_guid></audit><device><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.Device</type></__metadata><is_charging>false</is_charging><is_charged>false</is_charged><communications><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.communications</type></__metadata><is_communication_available>false</is_communication_available><communication_duration>0</communication_duration></communications><location><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.Location</type></__metadata><address><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.Address</type></__metadata><addressline><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.Addressline</type></__metadata></addressline></address><geocode><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.Geocode</type></__metadata><latitude>0.000000</latitude><longitude>0.000000</longitude><height>0.000</height><positional_uncertainty>0.000000</positional_uncertainty><is_containment>false</is_containment><precision>0</precision></geocode></location></device><to_container><__metadata><type>ZGW_CONTAINER_TRIP_EVENT_SRV.To_container</type></__metadata></to_container><container_trip_id>338760110225</container_trip_id><container_trip_guid>00000000-0000-0000-0000-000000000000</container_trip_guid><container_id>TRK186345678</container_id><container_type>TRK1</container_type><container_full_barcode>80049312650TRK186345678A</container_full_barcode><container_sealed>false</container_sealed><system_item_counter>2</system_item_counter><manual_item_counter>0</manual_item_counter><container_gross_weight_kg>0.00</container_gross_weight_kg><is_active>true</is_active><available_to_load_into>true</available_to_load_into><can_be_loaded_as_child>false</can_be_loaded_as_child><security_seal_ids><results><__metadata><id> </id></__metadata><seal_id>AA0000000001</seal_id></results><results><__metadata><id> </id></__metadata><seal_id>AA0000000002</seal_id></results><results><__metadata><id> </id></__metadata><seal_id>AA0000000002</seal_id></results></security_seal_ids><trip_legs><results><__metadata><id>http://hxaix48.hq.auspost.com.au:8001/sap/opu/odata/SAP/ZGW_CONTAINER_TRIP_EVENT_SRV/trip_legsSet(container_trip_id='',origin_facility_code='201531',event_type='')</id><uri>http://hxaix48.hq.auspost.com.au:8001/sap/opu/odata/SAP/ZGW_CONTAINER_TRIP_EVENT_SRV/trip_legsSet(container_trip_id='',origin_facility_code='201531',event_type='')</uri><type>ZGW_CONTAINER_TRIP_EVENT_SRV.trip_legs</type></__metadata><origin_facility_code>201531</origin_facility_code><destination_facility_code>308371</destination_facility_code><origin_facility_name>COFFS HARBOUR DC</origin_facility_name><destination_facility_name>360 COLLINS ST PARCEL LOCKER</destination_facility_name></results></trip_legs><container_trip_event><__deferred><uri>http://hxaix48.hq.auspost.com.au:8001/sap/opu/odata/SAP/ZGW_CONTAINER_TRIP_EVENT_SRV/container_tripSet('338760110225')/container_trip_event</uri></__deferred></container_trip_event><facility><__deferred><uri>http://hxaix48.hq.auspost.com.au:8001/sap/opu/odata/SAP/ZGW_CONTAINER_TRIP_EVENT_SRV/container_tripSet('338760110225')/facility</uri></__deferred></facility></results></container_trip>

输出

{ "container_trip": [ { "originator": { "person": {}, "system": {} }, "container": { "product_group": {} }, "audit": { "em_last_event_guid": " 00000000-0000-0000-0000-000000000000”},“设备”:{“is_charged”:“假”,“is_charged”:“假”,“通信”:{“is_communication_available”:“假”,“通信持续时间”: “0”},“位置”:{“地址”:{“地址线”:{}},“地理编码”:{“纬度”:“0.000000”,“经度”:“0.000000”,“高度”:“0.000 ", "positional_uncertainty": "0.000000", "is_containment": "false",“精度”:“0”}}},“to_container”:{},“container_trip_id”:“338760110225”,“container_trip_guid”:“00000000-0000-0000-0000-000000000000”,“container_id”:“TRK186345678”, “container_type”:“TRK1”,“container_full_barcode”:“80049312650TRK186345678A”,“container_sealed”:“false”,“system_item_counter”:“2”,“manual_item_counter”:“0”,“container_gross_weight_kg”:“0.00”,“is_active” “:“真”,“available_to_load_into”:“真”,“can_be_loaded_as_child”:“假”,“security_seal_ids”:[{“seal_id”:“AA0000000001”},{“seal_id”:“AA0000000002”},{“seal_id”:“AA0000000002”}],“trip_legs”:[{“origin_facility_code”:“201531”,“destination_facility_code”:“308371”,“origin_facility_name”:“COFFS HARBOR DC”,“destination_facility_name” : "360 COLLINS ST PARCEL LOCKER" } ], "container_trip_event": {}, "facility": {} } ]

}

XSLT