需要使用c #nunit资产验证Json响应 [英] Need to verify Json response with c# nunit assets
本文介绍了需要使用c #nunit资产验证Json响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要验证来自Web服务的响应,因为Json与c#Nunit断言如
I've to verify response coming from a web service as Json with c# Nunit asserts like
Assert.AreEqual(Response.get(PARTICULAR FIELD), "expected value");
o / p就像
The o/p is like
{
"meta": {
"code": 200,
"status": "ok",
"expires_in": 60578
},
}
请建议我使用可重复使用的方法
Please suggest me a reusable method
推荐答案
导入后<啊ref =http://json.codeplex.com/> Json.NET [ ^ 你可以执行以下操作:
After you import Json.NET[^] package you can do the following:
dynamic json = JsonConvert.DeserializeObject(yourJsonAsString)
那么你可以预先形成你的断言
Then you can preform your asserts
这篇关于需要使用c #nunit资产验证Json响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文