I have JSON Array
and when it is displayed in ListView
on Android, it appears with special characters:
JSONgeneratedbyphp:
[{"id":"1","titulo":"X-Burg","descricao":"Hambúrguer,...","preco":"R$ 7,50","tipo":"0"},{"id":"2","titulo":"Dogão","descricao":"Salsicha,...:"R$ 7,50","tipo":"0"}...]
Code Java
summarized:
Converter:
private CardapioEntities convertCardapio(JSONObject obj) throws JSONException {
String titulo = obj.getString(TAG_TITULO);
String descricao = obj.getString(TAG_DESCRICAO);
String preco = obj.getString(TAG_PRECO);
String tipo = obj.getString(TAG_TIPO);
return new CardapioEntities(titulo, descricao, preco, tipo);
}
Get JSON
and play on ListView
private void _getCardapio(String result) {
try {
JSONArray json = new JSONArray(result);
for (int i = 0; i < json.length(); i++) {
CardapioEntities cardapioEntities = new CardapioEntities();
if (convertCardapio(json.getJSONObject(i)).getCardapioTipo().contains("0")) {
cardapioEntities.setCardapioTitulo(convertCardapio(json.getJSONObject(i)).getCardapioTitulo());
cardapioEntities.setCardapioDescricao(convertCardapio(json.getJSONObject(i)).getCardapioDescricao());
cardapioEntities.setCardapioPreco(convertCardapio(json.getJSONObject(i)).getCardapioPreco());
listaLanches.add(cardapioEntities);
}
}
final ListView lvLanches = (ListView) findViewById(R.id.lvLanches);
lvLanches.setAdapter(new CustomListAdapter(this, listaLanches));
} catch (JSONException e) {
e.printStackTrace();
}
}
Tips and examples of improvements are always welcome.