Error generating a JSON object

1

I'm trying to create this object:

{
    "schema": [
        "urn:ietf:params:scim:schemas:core:2.0:User",
        "urn:ietf:params:scim:schemas:core:2.0:User",
        "urn:ietf:params:scim:schemas:core:2.0:User"
    ],
    "endereco": "Rua 0",
    "nome": "Fulano",
    "sobrenome": "de Tal"
}

but it looks like this:

{
    "{\"schema\":[\"urn:ietf:params:scim:schemas:core:2.0:User\",\"urn:ietf:params:scim:schemas:core:2.0:User\",\"urn:ietf:params:scim:schemas:core:2.0:User\"]}": {
        "endereco": "Rua 0",
        "nome": "Fulano",
        "sobrenome": "de Tal"
    }
}

My Code

import org.json.simple.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;


public class Main {

    public static void main(String[] args) throws JSONException {


        JSONArray arr = new JSONArray();
        JSONArray headers = new JSONArray();
        JSONObject usuario = new JSONObject();
        JSONObject head = new JSONObject();
        JSONObject obj = new JSONObject();

        usuario.put("nome", "Fulano");
        usuario.put("sobrenome", "de Tal");
        usuario.put("endereco", "Rua 0");

        headers.put("urn:ietf:params:scim:schemas:core:2.0:User");
        headers.put("urn:ietf:params:scim:schemas:core:2.0:User");
        headers.put("urn:ietf:params:scim:schemas:core:2.0:User");



        head.put("schema", headers);

        obj.put(head, usuario);

        System.out.println(obj);
    }

}
    
asked by anonymous 21.11.2017 / 17:15

1 answer

1

The logic is incorrect, because you are creating a user object, and adding it next to the head, and the head has no value, just do so

    obj.put("nome", "Fulano");
    obj.put("sobrenome", "de Tal");
    obj.put("endereco", "Rua 0");
    
21.11.2017 / 20:21