简体   繁体   中英

convert byte to string in javascript

I have a project where i used gzip in .cs file to zip the data. Here is my code.

public byte[] CustomerList()
{
    SqlDataAdapter da = new SqlDataAdapter("select CustomerID from CustomerMaster", con);

    DataSet ds = new DataSet();
    da.Fill(ds);
    return CompressData(ds);
}
public byte[] CompressData(DataSet ds)
{
    using (MemoryStream memory = new MemoryStream())
    {
        using (GZipStream gzip = new GZipStream(memory, CompressionMode.Compress))
        {
            var formatter = new BinaryFormatter();
            formatter.Serialize(gzip, ds);
            gzip.Close();
        }

        return memory.ToArray();
    }
}

I called this zip function form my js file and getting the data as a byte format.

<script type="text/javascript" language="javascript">
$(document).ready(function () {

                $.ajax({
                    type: "POST",
                    url: "Service1.svc/CustomerList",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    processdata: true,
                    success: function (data) {
                        alert(data.CustomerListResult);
                    },
                    error: function () {
                        alert("Error");
                    }
                });
            });

Now i want to decrypt this [byte-data] to get the original string. Here the issue started. How should i get the original data that means how i would decrypt or unzip the [byte data] to get the original string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM