不带引号的json属性名称 [英] Unquoted json property name

查看:96
本文介绍了不带引号的json属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NewtonSoft的Json.Net解析器的功能之一是支持不带引号的属性名,例如{test:"abc"}.是否可以关闭此功能,以便json解析器在解析带有未引用属性名称的json字符串时会引发错误?

One of the features in NewtonSoft's Json.Net parser is the support of unquoted property name, for example {test:"abc"}. Is it possible to turn off this feature so the json parser will throw an error when it parses a json string with unquoted property name?

推荐答案

您可以做的是反序列化,然后再次序列化并与原始输入进行比较.这样可以检测到缺少的引号.即使这不是高效的性能,它也非常简单,并且在相关的代码性能无关紧要时可以很好地发挥作用.

What you can do is to deserialize and then serialize again and compare with original input. That will detect missing quotes. Even if this is not performance efficient, it is very simple and serves well when the relevant code performance does not matter much.

这篇关于不带引号的json属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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