私は奇妙な問題をデシリアライズしています。粗いコードは申し訳ありませんが、これはプロトタイプを意味していました。 モノトーンのシリアライゼーションの問題
は基本的に私は、単純なクラスをシリアル化と逆シリアル化しようとしています:[Serializable]
[Preserve(AllMembers=true)]
public class School
{
public School()
{
}
public string est_name{get; set;}
public string postcode{get; set;}
public string phase {get; set;}
public string head_name{get; set;}
public string urn {get; set;}
public long distance{get; set;}
public string coord{get; set;}
public string gender{get; set;}
public int totpup{get; set;}
public int totelig{get; set;}
public float pmattest14p{get; set;}
public float pmattest15{get; set;}
public float pengtest14p{get; set;}
public float pengtest15{get; set;}
public float apsengmattest{get; set;
}
使用して、次のようにシリアライズのためのコードがある学校[] T、そのジェネリッククラスのメソッドとして:
デシリアライズコードはAである<?xml version="1.0" encoding="utf-8"?>
<ArrayOfSchool xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<School><est_name>testName</est_name><postcode>N7 0NA</postcode><head_name>thedude</head_name><distance>0</distance><gender>mixed</gender><totpup>0</totpup><totelig>0</totelig><pmattest14p>0</pmattest14p><pmattest15>0</pmattest15><pengtest14p>5</pengtest14p><pengtest15>3</pengtest15><apsengmattest>0</apsengmattest></School><School><est_name>testName2</est_name><postcode>N7 4NA</postcode><head_name>thedude</head_name><distance>0</distance><gender>mixed2</gender><totpup>0</totpup><totelig>0</totelig><pmattest14p>0</pmattest14p><pmattest15>0</pmattest15><pengtest14p>5</pengtest14p><pengtest15>3</pengtest15><apsengmattest>0</apsengmattest></School></ArrayOfSchool>
:以下のXMLファイルで得
public void serializesample(T sample)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Sample2.xml") Stream st = new FileStream(path, FileMode.OpenOrCreate);
XmlWriter w = new XmlTextWriter(st, Encoding.UTF8);
serializer.Serialize(w, sample);
st.Flush();
st.Close();
}
sがTとして[]学校で、次の:
private T ReadObject(XmlReader reader)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
return (T)serializer.Deserialize(reader);
}
XmlReader r = XmlReader.Create(new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Sample2.xml"), FileMode.Open));
e.responseObject = ReadObject(r);
私は最後の上場ライン "responseObject =のreadObject(R);" で次の例外を取得しておいてください。
のSystem.InvalidOperationException:エラーがありますXML文書の中で。 System.InvalidOperationException:System.InvalidOperationException:(不明)が予想されない at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot(System.Xml.Serialization.XmlTypeMapping rootMap)[0x00050] in/Developer/MonoTouch/Source/mono/mcs /クラス/ System.XML/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs:182 at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot()[0x00028] in /Developer/MonoTouch/Source/mono/mcs/class/System.XML/Developer/MonoTouch/Source/mono/mcs/class /内のSystem.Xml.Serialization.XmlSerializer.Deserialize(System.Xml.Serialization.XmlSerializationReaderリーダー)の[0x0001c]での/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs:87 System.XML/System.Xml.Serialization/XmlSerializer.cs:361 ---内部例外スタックトレースの終了--- at System.Xml.Serialization.XmlSerializer.Deser ialize(System.Xml.Serialization.XmlSerializationReaderリーダー)[0x00061] /Developer/MonoTouch/Source/mono/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:366 at System.Xml.Serialization .XmlSerializer.Deserialize(System.Xml.XmlReader xmlReader)[0x0002c] /Developer/MonoTouch/Source/mono/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs:350 (Burnspeed.Utilities) WebRequestHelper 1[SchoolFinder_Prototype.School[]].ReadObject (System.Xml.XmlReader stream) [0x00010] in /Users/Khalil/Desktop/Monotouch Utility/Burnspeed.Utilities/Burnspeed.Utilities/WebRequestHelper.cs:201 at Burnspeed.Utilities.WebRequestHelper
1 [SchoolFinder_Prototype.School []] ProcessHttpResponseAndFire(たIAsyncResult IAR)[0x000ae]で/ユーザ/カリル/デスクトップ/ MonoTouchでユーティリティ/ Burnspeed.Utilities/Burnspeed.Utilities/WebRequestHelper.cs:156