can guide me how convert jsonwriter jsonobject in gson without predefined object.
jsonwriter writer = new jsonwriter(new filewriter("c:\\users\\ravr\\desktop\\outputjsonschema.json")); writer.setindent( " " ); writer.beginobject(); writer.name( "$schema" ).value( "http://json-schema.org/draft-04/schema#" ); writer.name( "type" ).value( "object" ); writer.name("properties"); writer.beginobject();//1properties start writer.name( "country" ); writer.beginobject();//2emp start writer.name( "type" ).value( "array" ); writer.name( "minitems" ).value(0); writer.name( "maxitems" ).value("undefined"); writer.name( "items" ); writer.beginobject();//3 emp item start writer.name( "type" ).value( "object" ); writer.name( "properties" ); writer.beginobject();// writer.name( "id" ); writer.beginobject();// 5 emp id start writer.name( "type" ).value( "string" ); writer.endobject(); // 5 emp id end writer.name( "name" ); writer.beginobject();// 5 emp id start writer.name( "type" ).value( "string" ); writer.endobject(); // 5 emp id end writer.endobject(); writer.endobject();//3 emp item end writer.name( "required" ); writer.beginarray(); writer.value( "id" ); writer.value( "name" ); writer.endarray(); writer.endobject();//2emp end writer.endobject();//1properties end writer.endobject(); writer.flush();
quick , dirty solution use stringwriter
instead of file writer:
stringwriter sw = new stringwriter(); jsonwriter writer = new jsonwriter(sw); // .. writing code jsonobject obj = new jsonparser().parse(sw.tostring()).getasjsonobject();
otherwise use like:
jsonobject obj = new jsonobject(); obj.add("name", jsonelement); obj.addproperty("othername", "value");
Comments
Post a Comment