REST服务JSON响应. [英] REST services JSON response.

查看:69
本文介绍了REST服务JSON响应.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,

在REST服务中,我创建的[DataContract]如下所示:

Hii,

In the REST services I have created my [DataContract] looks like this :

[DataContract]
public class Emp
{
[DataMember]
public Guid Eid {get;set;}
[DataMember]
public string Ename{get;set;}
[DataMember]
public DateTime CreatedDate{get;set;}

}



我从数据库(SQL)中检索结果,并基于Eid检索"Ename"值.我编写了SQL查询,它的工作正常.我重述了一个列表.现在,我想将其显示为JSON响应.但是我可以像这样清晰地查看XML响应:



I am retrieving the results from database(SQL) and I am retrieving "Ename" value based on Eid.I wrote SQL query and its working fine.I am returing a list .Now I want to display it as JSON response .However I can view the XML response clearly like this :

<Eid>00000000-0000-0000-0000-000000000000</Eid>
<Ename>John</Ename>
<CreatedDate>0001-01-01T00:00:00</CreatedDate>
When I decorate my OperationContract like this 
 [OperationContract]
        [WebInvoke(UriTemplate = "GetEName/?id={eid}", Method= "GET",ResponseFormat=WebMessageFormat.Json)]
        Emp GetName(Guid eid); 


并运行该应用程序,然后出现错误:"[Fiddler] ReadResponse()失败:服务器未对此请求返回响应."

我想这只是因为浏览器在JSON响应中未将默认日期设为0001-01-01T00:00:00

返回的日期为0001-01-01T00:00:00时,如何纠正此错误并获得响应?我需要对代码(DataContract)进行哪些修改?

在此先感谢...


and run the application then I am getting error:"[Fiddler] ReadResponse() failed: The server did not return a response for this request."

I guess this is only because browser is not taking default date to be 0001-01-01T00:00:00 in JSON response

How can I make this corrected and get the response when the returned date is 0001-01-01T00:00:00?What are the modifications I have to do in the code(DataContract) ?

Thanks in advance...

推荐答案

hiii,
请参阅此链接

如果日期为空,则将其替换为空白

带有JSON的WCF REST服务 [
hiii,
refer this link

if date is null then just replace it with blank space

WCF REST Service with JSON[^]


这篇关于REST服务JSON响应.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆