根据 XML Schema (XSD) 验证 JSON [英] Validate JSON against XML Schema (XSD)

查看:33
本文介绍了根据 XML Schema (XSD) 验证 JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Java 中使用 XSD 验证 JSON?我有一个接收 JSON 响应的应用程序,我想根据现有的 XSD 对其进行验证.我的应用程序的另一部分使用 XML,这就是为什么如果它们都可以针对现有的 XSD 进行验证将是最简单的.

Is it possible to validate JSON with an XSD in Java? I have an application where I receive JSON response, and I would like to validate it against existing XSD. Another part of my application uses XML, which is why it would be easiest if they both could validate against the existing XSD.

推荐答案

, XML Schema (XSD) 用于验证 XML;要验证 JSON,请参阅 JSON 架构.

No, XML Schema (XSD) is for validating XML; to validate JSON, see JSON Schema.

我建议手动生成架构,以便完全理解和完全控制约束.但是,这里有一些可以快速启动流程的自动化工具:

I recommend generating schemas by hand for full understanding and full control over the constraints. However, here are some automated tools that can jumpstart the process:

相关且非常有用:

  • 从 XML 解析为 JSON(解组)或将 JSON 序列化为 XML(元帅),请参阅 JSONIX.
  • 有关实现列表(包括各种语言的验证器),请参阅 JSON-Schema 实现.

这篇关于根据 XML Schema (XSD) 验证 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆