我有一个json文件,但我只使用从xml文件导入数据的应用程序。那么有人知道将json文件转换为xml的工具吗?我一直在寻找这样的工具几个小时,只能找到从xml创建json文件的工具。
谢谢!
答案 0 :(得分:0)
如果您使用的是.NET Framework,则可以在代码中执行此操作:
注意事项:
答案 1 :(得分:0)
纯XSLT 2.0实施:
查看f:json-document()
中的FXSL 2.x library。
使用此函数非常容易合并JSon并将其用作... XML。
例如,可以编写以下XPath表达式:
f:json-document($vstrParam)/Students/*[sex = 'Female']
和让Students
的所有孩子都拥有sex = 'Female'
以下是完整示例:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:f="http://fxsl.sf.net/"
exclude-result-prefixes="f xs"
>
<xsl:import href="../f/func-json-document.xsl"/>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vstrParam" as="xs:string">
{
"teacher":{
"name":
"Mr Borat",
"age":
"35",
"Nationality":
"Kazakhstan"
},
"Class":{
"Semester":
"Summer",
"Room":
null,
"Subject":
"Politics",
"Notes":
"We're happy, you happy?"
},
"Students":
{
"Smith":
{"First Name":"Mary","sex":"Female"},
"Brown":
{"First Name":"John","sex":"Male"},
"Jackson":
{"First Name":"Jackie","sex":"Female"}
}
,
"Grades":
{
"Test":
[
{"grade":"A","points":68,"grade":"B","points":25,"grade":"C","points":15},
{"grade":"C","points":2, "grade":"B","points":29, "grade":"A","points":55},
{"grade":"C","points":2, "grade":"A","points":72, "grade":"A","points":65}
]
}
}
</xsl:variable>
<xsl:template match="/">
<xsl:sequence select=
"f:json-document($vstrParam)/Students/*[sex = 'Female']"/>
</xsl:template>
</xsl:stylesheet>
当对任何XML文档应用上述转换(忽略)时,会生成正确的结果:
<Smith>
<First_Name>Mary</First_Name>
<sex>Female</sex>
</Smith>
<Jackson>
<First_Name>Jackie</First_Name>
<sex>Female</sex>
</Jackson>