Convert to JSON Java Script

-2

I am working on Java JSP and JavaScript, and I need to convert the result of a DataStore query format:

<Entity [Usuario(5523854313120)]:
    Email = [email protected]
    PrimerNombre = Andres
    Rol = Administrador
   Password = andres125
>

to JSON format:

{"Email ":"[email protected]","PrimerNombre ":"Andres","Rol ":"Administrador", "Password":"andres125"}

This is the code:

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Query q=new Query("Usuario");
PreparedQuery pq = datastore.prepare(q);
Entity result=pq.asSingleEntity();
    
asked by afar1793 11.01.2018 в 15:21
source

2 answers

0

The ideal would be to convert this object to a common java object and then use the Jackson java library as indicated here.

link

Greetings ...

    
answered by 19.01.2018 в 12:16
0

It also depends on how you are showing the data in the jsp.

  • If you are using REST Api, you can use jackson and he is in charge of parsing the model from java to json. Here is a simple example: JSON Example with jersey jackson
  • If you are running the java code from the jsp, then I recommend these two resources using jackson:

Greetings !!!.

    
answered by 16.03.2018 в 20:10