Search code examples
javajsonmicroservices

Multiple JsonObject in one .put


I'm having problem adding a json to the java code, I have these parameters

The compiler shows error, could you help me

.put("person",new JsonObject().put("name",("Luis"), new JsonObject().put("phoneNumber",("526677777777"))))

JSON :

"person": {
"name": "Luis",
"phoneNumber": "526677777777"
}

The error reports is_:

Error:(147, 47) java: no suitable method found for put(java.lang.String,java.lang.String,io.vertx.core.json.JsonObject)


Solution

  • It seems that you are trying to add too much of values ot the json and there's no method with three params in a signature. I think there's an error in your code.

    put("name",("Luis"), new JsonObject().put("phoneNumber",("526677777777")))
    

    there's defenetelly an error with that ("Luis")

    Maybe it should be something like that:

        JsonObject person = new JsonObject();
        person.put(new  JsonObject("name", "Luis"));
        person.put(new  JsonObject("phoneNumber", "526677777777"));