Json Correct format for typeahead?

0

When generating 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?

    
asked by anonymous 20.07.2015 / 13:08

1 answer

1

Would not that be correct?

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 . Is that it?

    
20.07.2015 / 15:34