private static void WriteJson(string filepath,
string filename,
JsonSchema jsonschema)
{
using (TextWriter writer = File.CreateText(
@"C:\Users\ashutosh\Desktop\Output\" + filename + ".js"))
using (var jtw = new JsonTextWriter(writer))
{
jtw.Formatting = Formatting.Indented;
jsonschema.WriteTo(jtw);
}
//var json = JsonConvert.SerializeObject(
// jsonschema, Formatting.Indented,
// new JsonSerializerSettings {
// NullValueHandling = NullValueHandling.Ignore });
// File.WriteAllText(
// @"C:\Users\ashutosh\Desktop\Output\" + filename + ".js", json);
}
我正在从 JSON.net 创建一个 JSONSchema,然后将其写出来。我得到一个
Invalid Operation Exception Sequence contains no matching element
但是当我使用注释代码而不是通常的东西时。没有出现这样的异常。
1)是什么导致了这个异常?2)我会很高兴地使用第二种方法,但感觉不直观,它会打印出 JsonType 的整数值,用于 schema.Type 而不是(数组,整数,布尔等)
我该怎么做才能摆脱这种情况?
更新当has count = 0
的 " Properties
" 属性
时发生异常。是。我已经对其进行了初始化,因此它不为空。最终,代码可能会也可能不会向其中添加元素。因此,计数可能保持为 0。JsonSchema
Properties
Dictionary<String,JsonSchema>