c#


How to convert a 2D binary object in to a Dictonary<string, object> in C# using Binary Formatter


I want to convert an objeect of byte[][] type to Dictonary.
It always give an error "End of Stream encountered before parsing was completed."
Please help me .
public static object ByteToObjectArray(byte[][] ms)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream mStream = new MemoryStream();
mStream.Write(ms, 0, (int)ms.Length);
mStream.Position = 0;
return formatter.Deserialize(mStream) as object;
}
The HGETALL should return the data as
key1
data1
key2
data2
...
So interleaved... Now... Supposing the key is in UTF8:
public static Dictionary<string, object> ByteToObjectArray(byte[][] bytes)
{
var dict = new Dictionary<string, object>();
var formatter = new BinaryFormatter();
for (int i = 0; i < bytes.Length; i += 2)
{
string key = Encoding.UTF8.GetString(bytes[i]);
// Alternatively
//string key = Encoding.Unicode.GetString(bytes[i]);
using (var stream = new MemoryStream(bytes[i + 1]))
{
object obj = formatter.Deserialize(stream);
dict.Add(key, obj);
}
}
return dict;
}

Related Links

Remember client device
Receiving user input from do while statement
How do I append data to memcached using Enyim.Caching in C#?
Asp.net WebAPI XML deserialize?
What are differences in purposes and contents between ECMA-335 and ISO/IEC 23271:2012 as CLI standards?
convert long binary data in database access to image using c#
touch control to move cube (in an array that generates them) left and right
DataGrid displaying content value of 'System.Data.DataRowView'
Selenium does not execute click command
Check whether array is in another array, but in order and elements can repeat [duplicate]
Cannot get ClickOnce app to deploy if I pass arguments
Exception thrown: 'System.ApplicationException' in renderdocui.exe
Dynamic drawing multiple shapes - WinForm [duplicate]
OData $expand Contains Incorrect Context Link
Using JSON.NET to read a dynamic property name
Animating a Control using a sine wave

Categories

HOME
qlikview
virtual-machine
weblogic
microcontroller
ebay-api
stdout
arguments
esxi
sms
download
localhost
mediarecorder
rmarkdown
yacc
jetbrains
drush
cakephp-2.0
opendaylight
alert
loader
gpo
multipart
gnu-screen
screen-scraping
v4l2
cloudformation
bytebuffer
git-submodules
hierarchy
recreate
jql
urhosharp
dropdownbox
gitosis
blueimp
office-interop
fisheye
file-descriptor
php-mongodb
wufoo
logan-square
anonymous-function
react.rb
flask-socketio
node-java
reloaddata
spring-cloud-aws
breadcrumbs
stringbuilder
easy-thumbnails
qudpsocket
gevent
virtualenvwrapper
deck.js
hfp
stdlist
apache2-module
sqldataadapter
askbot
autopep8
firebase-tools
pymol
mri
nsq
xmlserializer
ios-enterprise
amzi-prolog
mvcgrid
cvi
node-mongodb-native
nomachine
octokit
http-compression
outlook-object-model
ntdll
yii-components
webpage-screenshot
databus
winrt-async
socketasynceventargs
inserthtml
mscorlib
cherokee
service-layer
nstoolbar
google-local-search
chromebug
pitch-shifting
dynamic-scope
ihtmldocument2
scalable

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App