如何停止格式化Json数据2次。 [英] How to stop formatting Json data 2 times.

查看:178
本文介绍了如何停止格式化Json数据2次。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用WCF REST服务,将数据作为Json格式返回。对于我的一种方法,声明如下所示,



 <   operationcontract, > POST,ResponseFormat:= WebMessageFormat.Json,BodyStyle:= WebMessageBodyStyle.Wrapped ,UriTemplate:=GetExpenseSnapshot)> 
函数GetExpenseSnapshot(ByVal sessionkey As String,ByVal expenseReportID As Integer)As ExpenseReportSnapShot



在我的实现中,我手动将数据格式化为Json格式。当我调试和检查时,数据显示正确但在检查WCF客户端时,数据显示错误,即为每列添加@符号和额外的双引号()。

<例如,

 @{评论:[{行:[{XmlLabel :RestService.EXPEntity,expenseReportID:,expReportNotesID:
}]}]}





但我需要这样显示,

 {评论:[{行:[ {XmlLabel:RestService.EXPEntity,expenseReportID:,expReportNotesID:
}]}]}





请帮我解决这个问题...

谢谢

Teja MS。

解决方案

< blockquote>你可以通过尝试反序列化对象来检查

 JsonConvert.DeserializeObject< YourReturnDataType>(YourResult)

Hi All,

I am working on WCF REST Service with returning data as Json format. For one of my method, declaration as shown below,

<operationcontract,>"POST", ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.Wrapped, UriTemplate:="GetExpenseSnapshot")>
        Function GetExpenseSnapshot(ByVal sessionkey As String, ByVal expenseReportID As Integer) As ExpenseReportSnapShot


and in my implementation, i manually formatting the data as Json format. When i debug and check, the data was displayed correctly but when checking in WCF Client, the data was displayed wrongly i.e adding "@" symbol and extra double quotes ("") for each column.

For example,

 @"{""Comment"" : [{""Row"":[ {""XmlLabel"":""RestService.EXPEntity"",""expenseReportID"":"""",""expReportNotesID"":""""
}]}]}""



but i need to display like this,

  {"Comment" : [{"Row":[ {"XmlLabel":"RestService.EXPEntity","expenseReportID":"","expReportNotesID":""
}]}]}



Please help me to resolve this...
Thanks
Teja MS.

解决方案

You can check by trying to deserialize the object

JsonConvert.DeserializeObject<YourReturnDataType>(YourResult)


这篇关于如何停止格式化Json数据2次。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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