如何反序列化 WCF 数据服务 (OData) 返回的 JSON
外部 OData 服务在 POST 操作期间返回以下内容(对于服务操作):
{
"d" : {
"__metadata": {
"uri": "http://dd-1620/ServiceData.svc/Customers('1001')", "type": "DataModel.Customer"
}, "MasterCustomerId": "1001", "SubCustomerId": "0", "FirstName": "Jag", "LastName": "Chat"
}
}
我编写了以下内容来反序列化上述内容:
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream respStream = resp.GetResponseStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ReturnType));
ReturnType oRespCus = (ReturnType)ser.ReadObject(respStream);
现在,oRespCus 确实已实例化。但是,所有字段都设置为空。
谁能帮我解决这个问题。
谢谢
An external OData Service returns the following during a POST operation (for a service operation):
{
"d" : {
"__metadata": {
"uri": "http://dd-1620/ServiceData.svc/Customers('1001')", "type": "DataModel.Customer"
}, "MasterCustomerId": "1001", "SubCustomerId": "0", "FirstName": "Jag", "LastName": "Chat"
}
}
I wrote the following to deserialize the above:
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream respStream = resp.GetResponseStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ReturnType));
ReturnType oRespCus = (ReturnType)ser.ReadObject(respStream);
Now, oRespCus is indeed instantiated. However, with all fields set to null.
Can anyone help me on this.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于那些不知道的人,我想分享我从这里收到的答案
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/55b6f018-2944-4160-8393-62a14376c361
谢谢大家。
For those who do not know, I would like to share the answer I received from here
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/55b6f018-2944-4160-8393-62a14376c361
thanks all.