dictionary <string, object>
オブジェクトに int、bool などの基本型が含まれる可能性がある場所、または別の配列が含まれる可能性がある場所の配列を返そうとしています。dictionary<string, object>
正常にシリアライズできますが、ディクショナリ内にディクショナリがある場合、デシリアライズされません。
次のエラーが表示されます。
Error in line 1 position 543. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value' contains data from a type that maps to the name 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfArrayOfKeyValueOfstringanyType'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'ArrayOfArrayOfKeyValueOfstringanyType' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.
クラス:
[DataContract(Namespace = "CISICPD")]
[KnownType(typeof(Dictionary<string,object>))]
public class TestResponse
{
[DataMember]
public Dictionary<string,object>[] Results;
}
関数:
public TestResponse test(string test1, string test2)
{
TestResponse r = new TestResponse();
r.Results = new Dictionary<string, object>[1];
r.Results[0] = new Dictionary<string, object>();
r.Results[0].Add("field1", 26);
Dictionary<string, object>[] d = new Dictionary<string, object>[1];
d[0] = new Dictionary<string, object>();
d[0].Add("inner", 28);
r.Results[0].Add("dictionary", d);
return r;
}
これを実行するとエラーメッセージが表示されますが、正しい既知のタイプを取得したと思いますか?
CISICPD.CPDClient t = new CISICPD.CPDClient();
CISICPD.TestResponse response = t.test("dgdf", "dfsdfd");