Print objecto json with good fromato

1

I have the following function that what it does is to bring me a list from the webservice, then that list is converted into an XML string since the list that returns is a soap response. after that what I do that string to json and get something like this.

{"ListaMaterias":[{"nombreMateria":"Biologia","codigoMateria":3525,"id":1,"descMateria":"Aprender Biologia"},{"nombreMateria":"Quimica","codigoMateria":3678,"id":2,"descMateria":"Aprender Quimica"}]}

How can I make a better impression format for the json object? for example, print it as a kind of table?

function code:

'    public static void main(String[] args) {

    List resultado = null; 
    resultado = new ArrayList<>();
    resultado = listarDatos();
    XStream xstream = new XStream();
    String xml = xstream.toXML(resultado);

    String xml_m = xml.replace("<list>", "").replace("</list>", "").replace("<newwebservicematerias.Materia>", "<ListaMaterias>").replace("</newwebservicematerias.Materia>", "</ListaMaterias>");

    JSONObject soapDatainJsonObject = XML.toJSONObject(xml_m);
    System.out.println(soapDatainJsonObject);

    /*Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String jsonString = gson.toJson(soapDatainJsonObject);
    System.out.println(jsonString);*/

}'
    
asked by juancamilovallejos0 19.04.2018 в 00:29
source

1 answer

0

You could try with the Interface JsonParser of Java. The java documentation can help you understand a bit better how to format the JSON objects. link

    
answered by 19.04.2018 в 01:05