像我有它返回JSON結果的方法:如何解析JSON對象
return Json(new { status = "error", message = "The organization cannot be deleted because contains transmitters!" });
現在我想用狀態和消息來測試我有這個
var result = Controller.DeleteOrganization(2) as JsonResult;
Assert.AreEqual("error", result.Data.message);
我試過越來越錯誤:
object does not contain a definition for message
我怎樣才能解決這個問題?
Data的類型爲'object',不會暴露該屬性。嘗試將Data屬性分配給一個'dynamic'變量,然後嘗試訪問該屬性。如果這不起作用,那麼我給了一個答案[這裏](http://stackoverflow.com/a/38446754/5233410)和[這裏](http://stackoverflow.com/a/38552771/5233410),你可以適應你的問題。 – Nkosi
是的,你是對的。謝謝:) –