![]() If (ExplicitDeserialization & !(CodeWriter is CSharpCodeWriter)) if (type2 = JsonTypeEnum.Dictionary) return type1 if (type2 = JsonTypeEnum.Object) return type1 Private JsonTypeEnum GetCommonTypeEnum(JsonTypeEnum type1, JsonType type2json) WriteClassesToFile(Path.Combine(folder, (UseNestedClasses & !type.IsRoot ? MainClass + "." : string.Empty) + type.AssignedName + CodeWriter.FileExtension), new ) If (s.StartsWith(Namespace + ".")) s = s.Substring(Namespace.Length + 1) If (!UseNestedClasses & !type.IsRoot & SecondaryNamespace != null) WriteClassesToFile(Path.Combine(TargetFolder, MainClass + CodeWriter.FileExtension), Types) If (writeToDisk & !NoHelperClass & ExplicitDeserialization) File.WriteAllBytes(Path.Combine(TargetFolder, "JsonClassHelper.cs"), ) Var parentFolder = System.IO.Path.GetDirectoryName(().Location) Var rootType = new JsonType(this, examples) Throw new Exception("Sample JSON must be either a JSON array, or a JSON object.") Using (var reader = new JsonTextReader(sr))Įxamples = ((JArray)json).Cast().ToArray() Using (var sr = new StringReader(example)) Var example = Example.StartsWith("HTTP/") ? Example.Substring(Example.IndexOf("\r\n\r\n")) : Example If (writeToDisk & !Directory.Exists(TargetFolder)) Directory.CreateDirectory(TargetFolder) If (used) throw new InvalidOperationException("This instance of JsonClassGenerator has already been used. If (ExplicitDeserialization & !(CodeWriter is CSharpCodeWriter)) throw new ArgumentException("Explicit deserialization is obsolete and is only supported by the C# provider.") If (CodeWriter = null) CodeWriter = new CSharpCodeWriter() Type.Fields = jsonFields.Select(x => new FieldInfo(this, x.Key, x.Value, UsePascalCase, fieldExamples)).ToArray() If (!(item.Value is JObject)) throw new NotSupportedException("Arrays of non-objects are not supported yet.") į(CreateUniqueClassNameFromPlural(field.Key)) If (!(item is JObject)) throw new NotSupportedException("Arrays of non-objects are not supported yet.") Įlse if (value.Type = JTokenType.Object) If (fieldType.InternalType != null & = JsonTypeEnum.Object) GenerateClass(subexamples.ToArray(), fieldType) If (obj.TryGetValue(field.Key, out value))įieldType.AssignName(CreateUniqueClassName(field.Key)) Var subexamples = new List(examples.Length) If (fieldType.Type = JsonTypeEnum.Object) Var v = val.Type = JTokenType.Array || val.Type = JTokenType.Object ? val : val.Value() If (val.Type = JTokenType.Null || val.Type = JTokenType.Undefined) If (first) commonType = commonType.MaybeMakeNullable(this) Įlse commonType = commonType.GetCommonType(JsonType.GetNull(this)) Var commonType = fieldType.GetCommonType(currentType) If (jsonFields.TryGetValue(propName, out fieldType)) ![]() Var currentType = new JsonType(this, prop.Value) This tool is currently in beta.Private void GenerateClass(JObject examples, JsonType type) It is easier to use, and provides an API. If you need to generate simple json objects (no tree or array), you can use our CSV data generator (You must select the JSON format). You have many tags available to generate your data.Some are more complex than others to use.The editor is not very user friendly, but on the other hand you can generate complex data. You can create complex JSON objects/arrays, with a tree structure of several levels.You can nest arrays inside objects, and vice versa. This JSON creator allows to generate json files. This dummy JSON generator allows you to meet these needs, you can generate JSON files with a few clicks. By generating dummy JSON files, developers can create sample data that can be easily shared with users. Sample Data: In some cases, developers may need to provide sample data for users to test their application.By generating dummy JSON files, developers can create test data sets to ensure that their applications work as expected. It is important to test the application's ability to handle various types of data. Testing: Sometimes it is necessary to have JSON data in order to make tests.There are several reasons to generate dummy JSON files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |