0
我有一个ArrayList在android中,我试图转换为Base64字符串,然后通过JSON和wcf服务将该字符串传递到一个wcf服务数据库。然后我需要能够从数据库读取它并在.NET应用程序中反序列化它。序列化android中的对象列表和反序列化在WCF
这是怎么了序列化android系统ArrayList中:
private String convertByteArrayToSave(byte[] b){
if(b != null){
return Base64.encodeToString(b,0,b.length,Base64.DEFAULT);
}else{
return "";
}
}
private String convertListToStringToSave(ArrayList<myClasses.Shape> myList){
ByteArrayOutputStream b = new ByteArrayOutputStream();
ObjectOutputStream out;
try {
out = new ObjectOutputStream (b);
out.writeObject(myList);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return convertByteArrayToSave(b.toByteArray());
}
然后在WCF服务我试图采取Base64编码字符串,并将其反序列化到列表(形状)和序列化到将其插入数据库。
Private Function ConvertAndroidByteToDotNet(ByVal s As String) As Byte()
Dim result As Byte() = Nothing
Dim b As Byte() = CType(System.Convert.FromBase64String(s), Byte())
Dim msTest As New MemoryStream(b)
msTest.Seek(0, SeekOrigin.Begin)
msTest.Position = 0
Dim formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
formatter.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
formatter.Binder = New BindChanger()
Dim shapelist As List(Of ColbyDataTypes.Shape) = DirectCast(formatter.Deserialize(msTest), List(Of ColbyDataTypes.Shape))
msTest.Close()
Dim bin As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
bin.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
bin.Serialize(msTest, shapelist)
result = msTest.ToArray()
Return result
End Function
的最终目标是要能够能够创建这些形状在.NET应用程序或Android应用程序的列表,并能够读取在.NET应用程序和Android应用列表无论身在何处它创建于。我可以当它从.NET创建Shape并使用WCF将其读入到Android中,但是在Android中创建它是我卡住的地方。我非常感谢任何帮助,谢谢。