JSON to JAVA Object

29 Nov '14, 07:21 PM
3,565 Views
Forum Forum Starter - Level 3

Hello.

I have a JSON: 

[
    {
        Estatus: true,
        Mensaje: "Accion valida",
        ap1: "DAVALOS",
        ap2: "ANDRADE",
        nombre: "JAIME",
        validacion: "1"
    }
]

 

And I need to pass this Fields to a FORM with separated fields. 

I try many diferent code like Jackson, but seems does not works. 

 

Regards.

 
x 1
Follow
Answer Answer at this question and get points!
Forum Hero - Level 9

Hi Rafael, if you have a json text, you can create a script component and read the json text with the json library, for example:

 

#input String jsontext
 

import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;

        String jsont= jsontext
        try {
            String genreJson = jsont;
            JSONObject genreJsonObject = (JSONObject) JSONValue.parseWithException(genreJson);
            System.out.println("Estatus "+genreJsonObject.get("Estatus"))

            System.out.println("Mensaje "+genreJsonObject.get("Mensaje"))

            System.out.println("ap1"+genreJsonObject.get("ap1"))

            System.out.println("ap2"+genreJsonObject.get("ap2"))

            System.out.println("nombre"+genreJsonObject.get("nombre"))
            System.out.println("validacion"+genreJsonObject.get("validacion"))

        } catch (ParseException  e) {
            e.printStackTrace();
        }
 

Best regards.

 
x 2
Forum Expert - Level 6

Hi Rafael,

if you're using WebRatio 7.2.6+ you can easily write a JSON document into an entity using the JSON I/O Operation available inside the Service Components menu.

So, as a solution to your problem, you can write the JSON content to a volatile entity and then preload the Form using the data contained in this volatile entity.

Let me know if this works.

Regards,

Lucio 

 
x 0
Answer at this question and get points!

Related questions