11

I have a byte[] that i obtained using Object ArrayList<Obj>

Can anyone tell me how to convert my byte[] to Object ArrayList?

Coveting ArrayList like this:

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
oos = new ObjectOutputStream(bos);
 
oos.writeObject(mArrayList);//mArrayList is the array to convert
byte[] buff = bos.toByteArray();

asp.net json displaying weird results

I am having trouble displaying results recieved from asp.net WebMethod. I have a HTML template and fill in the results from JSON response. The problem is that the first response is being displayed once, the second is displayed 2 times, the third 4 times, the fourth 8 times and so on . Here is the jQuery (I need to reference "d" first because the response is comming from asp.net and they put it there automatically)

     function fnGetContent(keyword) {
            var NewKeyword = keyword.tag;
            var type = keyword.type
            var oldresults = $("#fillresultsdiv").html()
            $('#hidQueryType').val('tagsearch');
            $.ajax({
                type: "POST",  //GetEvents(iType As Integer, sSearch As String)
                url: "Default.aspx/GetEvents",
                data: "{'iType':'" + type + "','sSearch' : '" + NewKeyword + "' }",
                contentType: "application/json; charset=utf-8",
                dataType: "json",

                success: function (msg) {
                    var events = [];
                    var obj = $.parseJSON(msg.d);

                    $.each(obj.res, function() {
                        var newRow = $('.Template').clone();

                        // Now loop through the object
                        for (var prop in this) {
                            if (this.hasOwnProperty(prop)) {

                                // Lucky for you, the keys match the classes :)
                                $('.' + prop, newRow).text(this[prop]);
                            }
                        }
                        $('#fillresultsdiv').append(newRow);
                    });

There is only one entry in the JSON for each event, it is the jQuery code that is making this happen, sample response:

 {"d":"{\"res\":[{\"day\":\"26\",\"dayofweek\":\"Tue\",\"month\":\"Jun\",\"title\":\"Glen Hansard\"
       ,\"venue\":\"Vic Theatre\",\"time\":\"7:00 PM\",\"ticketurl\":
        \"http://seatgeek.com/glen-hansard-tickets/chicago-illinois....
4

2 に答える 2

18

これで、一方向の変換方法に関する情報が提供されました...必要なものは次のとおりです。

ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
try {
    @SuppressWarnings("unchecked")
    ArrayList<Object> list = (ArrayList<Object>) ois.readObject();
    ...
} finally {
    ois.close();
}
于 2012-06-26T19:36:12.523 に答える
-1

私はここで明白な答えに行くつもりです...

for(byte b : bytearray) {
  arraylist.add(new Byte(b));
}
于 2012-06-26T19:18:36.040 に答える