有谁能告诉我如何使用C#在WCF服务中解析这些数据?
{"syncresp": {
"synchdr": {
"sessionref": "1234567890"
"syncref": "20110327T012000"
},
"syncbody": {
"syncedrecs": [
{
"recloc": "plog,0,123",
},
{
"recloc": "plog,0,123",
}
],
"serverdata": [
{
"table": " book",
"action": "new",
"recdata": {
"pnum": "67890",
"fname": "ghgfhn"
"lname": "M"
.
.
.
},
},
{
"table": "pins",
"action": "new",
"recdata": {
"patid": 123,
"insprovid": 5,
"insnum": "X34567",
"effdate": "6/3/2011",
"expdate": "5/3/2012",
"status": "a",
},
},
]
}
}}
答案 0 :(得分:2)
如果你想创建一个可以在WCF中使用/生成这类数据的数据合约,那么看看http://blogs.msdn.com/b/carlosfigueira/archive/2011/01/11/inferring-schemas-for-json.aspx - 它有一个工具,它可以推断出#34;可以使用DataContractJsonSerializer对您的示例进行序列化/反序列化的相应类。
答案 1 :(得分:0)
这是一个非常简单的问题,所以在提出这些问题之前请阅读一些手册。 谷歌的第一个搜索结果:
http://blah.winsmarts.com/2009-12-How_to_parse_JSON_from_C-.aspx
JavaScriptSerializer jSerialize = new JavaScriptSerializer();
BusinessObjectType businessObject = jSerialize.Deserialize<BusinessObjectType>(configuration);