Deserealize JSON jqGrid results in Java

I have the JSON result : [“habilitado”:true,”centroDeCustos.codigo”:30,”centroDeCustos.nome”:”INCUBATORIO OVOS – IBIPOR?”,”_id_”:10,”habilitado”:true,”centroDeCustos.codigo”:31,”centroDeCustos.nome”:”FRIGORIFICO AVES – LONDRINA”,”_id_”:11, … etc ]How do i deserealize centroDeCustos.codigo and centroDeCustos.nomeMy classes@Deserializes( “application/json”, “json”, “text/javascript” )public class CustomJSONDeserealization implements Deserializer {public Object[] deserialize(InputStream inputstream, ResourceMethod resourcemethod) { GsonBuilder …

via Java Application Development Tutorial » Search Results » ajax:

Deserealize JSON jqGrid results in Java

I have the JSON result :
[“habilitado”:true,”centroDeCustos.codigo”:30,”centroDeCustos.nome”:”INCUBATORIO OVOS – IBIPOR?”,”_id_”:10,
“habilitado”:true,”centroDeCustos.codigo”:31,”centroDeCustos.nome”:”FRIGORIFICO AVES – LONDRINA”,”_id_”:11, … etc ]How do i deserealize centroDeCustos.codigo and centroDeCustos.nome
My classes
@Deserializes( “application/json”, “json”, “text/javascript” )
public class CustomJSONDeserealization implements Deserializer
public Object[] deserialize(InputStream inputstream, ResourceMethod resourcemethod)
GsonBuilder gs = new GsonBuilder();
Gson gson = gs.create();
StreamToString sts = new StreamToString();
try

BufferedReader br = new BufferedReader(new InputStreamReader(inputstream));

JSONArray js;
js = new JSONArray(sts.convertStreamToString(inputstream));
List rows = gson.fromJson(js.toString(), new TypeToken>().getType());

System.out.println(rows); // for test
} catch (Exception e)
e.printStackTrace();

return null;
}
}

class StreamToString
public String convertStreamToString(InputStream is) throws IOException

BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
sb.append(line + “n”);

is.close();
return sb.toString();
}
}

class Teste
public Boolean habilitado;
public CentroDeCustos centroDeCustos; // Is other Class

public class CentroDeCustos
private int codigo;
private String nome;

// implementation class
//My javascript post
$(document).ready(function()

$(“#salvarccustos”).click(function()
var idToDataIndex = jQuery(‘#listaccustos’).jqGrid(‘getGridParam’,’_index’);

var id;
for (id in idToDataIndex)
if (idToDataIndex.hasOwnProperty(id))
var mydata = $(“#listaccustos”).jqGrid(‘getGridParam’,’data’);

}

var postData = JSON.stringify(mydata);
alert(“JSON serialized jqGrid data:n” + postData);
$.ajax(
type: ‘POST’,
url: ‘/webdip/usuario/ccustos/salvar’,
contentType: ‘application/json’,
dataType: ‘json’,
processData: false,
data: postData,
success: function(result)
alert(‘sucesso’);
$(‘#listaccustos’).trigger(‘reloadGrid’);
,
error: function(XMLHttpRequest, textStatus, errorThrown)
alert(‘erro: ‘ + XMLHttpRequest.responseText);
return false;

});
});
});

For more info: Deserealize JSON jqGrid results in Java

Java Application Development Tutorial » Search Results » ajax

Deserealize JSON jqGrid results in Java

Share this post:

Related Posts

Leave a Comment