【发布时间】:2014-08-29 14:15:31
【问题描述】:
如何从这两个相似的 Json 结果中获取模型: 我尝试了各种方法,但仍然无法弄清楚。 提前谢谢...
eg : result.ImagePath
1.
{"Success":"True"ImagePath":"D:\Wyo\PH\TS\Images\Preview\Admin\Toy\Soli.jpg"}
"2.
ContentResult 作为 Json 传递
Content="{"Success":"True"ImagePath":"D:\Wyo\PH\TS\Images\Preview\Admin\Toy\Soli.jpg"}"
Controller's sent data :
ContentResult result = Content("{\"Success\":\"" + vm.Success + "\"ImagePath\":\"" + vm.ImagePath + "\"}");
result.ContentType = "application/json"; //-- "application/json" //- "text/plain"
JsonResult jsResult = Json(result, JsonRequestBehavior.AllowGet);
return jsResult; //result
【问题讨论】:
-
您的预期输出是什么?要将 JSON 转换为类对象吗?
-
只想从这个响应中获取 ImagePath (json)
-
对于频繁使用 json 的用户来说应该很容易,而不是在这里寻找 binding , ko 之类的东西,这里的两个属性都是简单的字符串,作为 json 传递。
-
如果有点奇怪那是为了学习过程。如何使其工作,不想更改结构,如果没有任何格式错误帮助我进行转换。谢谢
标签: asp.net-mvc json asp.net-mvc-5 json.net