Json Correct format for typeahead?

Asked

Viewed 107 times

0

When I Gero a JSON with the code below :

JSONObject jsonObject = new JSONObject();
try {
    jsonObject.put("Nome", c.getNome_fantasia().trim());
    jsonObject.put("Apelido", c.getNome_razao_social().trim());
    jsonArray.put(jsonObject);                

} catch (JSONException ex) {
    Logger.getLogger(ControllerLogicCliente.class.getName()).log(Level.SEVERE, null, ex);
    throw new RuntimeException("Erro pupulando Clientes", ex);                
}

The result is a JSON in the format:

[{"Nickname":"Flavio Benini","Name":"Flavio Benini"}]

But typeahead works with it in the format below:

{Name: ["Flavio Benini"],Surname: ["Flavio Benini"]}

How to generate it Suitable format for typeahead?

1 answer

1

It wouldn’t be right?

jsonObject = new JSONObject();
jsonObject.put("Nome", "Flavio Benini");
jsonArray.put(jsonObject);

jsonObject = new JSONObject();
jsonObject.put("Apelido", "Flavio Benini");
jsonArray.put(jsonObject);

[{"Name":"Flavio Benini"},{"Nickname":"Flavio Benini"}]

Since the format you passed is an invalid format for a json.

Json used by typeahead.js nhl.json. Would that be?

  • c.getNome_fantasia(). Trim() = "Flavio Benini" got it!! The error is the json delimiters!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.