C# 从ReadAsStreamAsync或ReadAsStringAsync反序列化到CRM实体
我正在通过C# 从ReadAsStreamAsync或ReadAsStringAsync反序列化到CRM实体,c#,deserialization,dynamics-crm,httpresponse,json-deserialization,C#,Deserialization,Dynamics Crm,Httpresponse,Json Deserialization,我正在通过httpresponsemessageresponse=Helper.SendRequest(…)调用Web API,我需要将响应反序列化到CRM实体注释的列表 我们尝试过的方法之一是使用reasastreamasync: List<Annotation> _listAnnotation = new List<Annotation>(); MemoryStream stream1 = (MemoryStream)response.Content.ReadAsSt
httpresponsemessageresponse=Helper.SendRequest(…)
调用Web API,我需要将响应
反序列化到CRM实体注释
的列表
我们尝试过的方法之一是使用reasastreamasync
:
List<Annotation> _listAnnotation = new List<Annotation>();
MemoryStream stream1 = (MemoryStream)response.Content.ReadAsStreamAsync().Result;
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<Annotation>));
ser.WriteObject(stream1, _listAnnotation);
stream1.Position = 0;
List<Annotation> lst = (List<Annotation>)ser.ReadObject(stream1);
jsonString
的值为
[{"Id":"00000000-0000-0000-0000-000000000000","LogicalName":"annotation","Attributes":[{"Key":"filename","Value":"Microsoft.SharePoint.Client.FileInformation"},{"Key":"documentbody","Value":"JVBERi0xLjUKJfv8/f4KNCAwIG9iago8PAovVGFicyAvUwovU3RydWN0UGFyZW50cyAwCi9QYXJlbnQgMyAwIFIKL1Jlc291cmNlcyA2IDAgUgo......g=="},{"Key":"mimetype","Value":"text/plain"}],"EntityState":null,"FormattedValues":[],"RelatedEntities":[]}]
但是它说不能创建和填充列表类型Microsoft.Xrm.Sdk.AttributeCollection。
我交换了实体
和注释
,但没有用
以下哪种方法更好,最接近我需要做的事情?请让我知道你的建议或答案。我已经被困在这里好几天了。非常感谢 我认为旧的“早期绑定类型”和Entity
与新的web api不兼容。您可以创建自己的POCO和/或应该有生成器可以使用webapi的元数据端点为您生成类。我不相信旧的“早期绑定类型”和实体
与新的web api兼容。您可以创建自己的POCO和/或应该有生成器,可以使用webapi的元数据端点为您生成类
[{"Id":"00000000-0000-0000-0000-000000000000","LogicalName":"annotation","Attributes":[{"Key":"filename","Value":"Microsoft.SharePoint.Client.FileInformation"},{"Key":"documentbody","Value":"JVBERi0xLjUKJfv8/f4KNCAwIG9iago8PAovVGFicyAvUwovU3RydWN0UGFyZW50cyAwCi9QYXJlbnQgMyAwIFIKL1Jlc291cmNlcyA2IDAgUgo......g=="},{"Key":"mimetype","Value":"text/plain"}],"EntityState":null,"FormattedValues":[],"RelatedEntities":[]}]