Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中反序列化JSON jqGrid结果_Java_Javascript_Json_Jqgrid - Fatal编程技术网

在Java中反序列化JSON jqGrid结果

在Java中反序列化JSON jqGrid结果,java,javascript,json,jqgrid,Java,Javascript,Json,Jqgrid,我有一个JSON结果: [{"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 ] 如何反序列化c

我有一个JSON结果:

[{"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 ]
如何反序列化centroDeCustos.codigo和centroDeCustos.nome

我的课

@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<Teste> rows = gson.fromJson(js.toString(), new TypeToken<List<Teste>>(){}.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
}
        $(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;
                    }
                });
            });
        });