Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 11 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
JSON 工具项目 (程序员指南)包含一个使用 JSON 模式验证 JSON 文件内容的工具。
另一种方法是验证运行 (JavaScript) JSON 架构验证器 使用 Rhino。
The JSON Tools project (Programmer's Guide) includes a tool to validate the contents of a JSON file using a JSON schema.
An alternative could be to validate running the (JavaScript) JSON Schema Validator using Rhino.
json-schema-validator (目前版本为 0.0.1,所以它处于 pre-alpha 状态)对我来说效果很好。请注意,它不是 100% 功能完整,但它仍然可以正确识别我的 json 内容中的许多错误。
The json-schema-validator (currently in version 0.0.1, so it's in a pre-alpha state) worked pretty well for me. Be aware that it is not 100% feature complete but it could still correctly identify a lot of errors in my json content.
@b.long 我发现这篇文章正在寻找一个非常特殊的解决方案来轻松验证字符串的内容是否具有 JSON(对象/数组)。我找不到任何适合我需要的图书馆。
JSON Tools 项目或 json-schema-validator 虽然提供了很多,但对于我的需求来说太大了。因此,我确实实现了我自己的解决方案,它构建在Java 中 JSON 的 JSON.org 参考实现。
我已经在使用 JSON.org 的代码,并且从技术上讲,所有这些功能都已经存在,因此我通过重用其代码添加了这个非常简单的功能。
我用它来轻松测试查询数据库的方法返回的字符串是否采用正确的 JSON 格式,否则如果格式错误并发布到客户端可能会导致它停止工作。
希望这对你有用,就像对我有用。
@b.long I came across this post looking for a very particular solution to easily verify if a String's content has a JSON (object/array). I couldn't find any library that would suit my needs.
JSON Tools project or json-schema-validator though offer a lot are too big for my needs. Thus I did implement my own solution that is build on top of JSON.org reference implementation of JSON in Java.
I have already been using the JSON.org's code and technically all this functionality was already there, thus I added this very simple functionality reusing its code.
I use it to easily test if the String returned by methods querying my database are formatted in proper JSON which otherwise if badly formatted and posted to a client might cause it to stop working.
Hope this is of use to you as it is to me.