
C# Web Api接口返回结果为标准json格式
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json

·
[System.Web.Http.HttpPost]
public HttpResponseMessage GetProduct([FromBody] dynamic json)
{
var product = new { success = true, errorMsg = "", data = "" };
string jsons = Convert.ToString(json);
var products = Post(jsons);//调用接口方法
ResultMsg res = JsonConvert.DeserializeObject<ResultMsg>(products);
bool succ =Convert.ToBoolean( res.success.ToString());
string mes = res.errorMsg.ToString();
string dataa = res.data.ToString();
if (succ==true)
{
product = new { success = true, errorMsg = mes,data=dataa};
}
else
{
product = new { success = false, errorMsg = mes, data = dataa };
}
HttpResponseMessage result = new HttpResponseMessage();
result.Content = new StringContent(JsonConvert.SerializeObject(product), Encoding.GetEncoding("UTF-8"), "application/json");
return result;
}
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
大概逻辑是调用这个方法,在此方法中在调用真正的接口方法,将返回值给设定一下格式基本就可以了。最基本的方法。




适用于现代 C++ 的 JSON。
最近提交(Master分支:6 个月前 )
9f40a7b4
Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 9.6.9 to 9.6.10.
- [Release notes](https://github.com/squidfunk/mkdocs-material/releases)
- [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/CHANGELOG)
- [Commits](https://github.com/squidfunk/mkdocs-material/compare/9.6.9...9.6.10)
---
updated-dependencies:
- dependency-name: mkdocs-material
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 9 小时前
d41ca94f
* :wrench: adjust CMake versions
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :wrench: install OpenSSL for CMake
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :wrench: install OpenSSL for CMake
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :wrench: install OpenSSL for CMake
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :wrench: install OpenSSL for CMake
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :wrench: install OpenSSL for CMake
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :hammer: clean up
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :memo: update documentation
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me> 9 小时前
更多推荐
热门开源项目
活动日历
查看更多
直播时间 2025-03-13 18:32:35

全栈自研企业级AI平台:Java核心技术×私有化部署实战
直播时间 2025-03-11 18:35:18

从0到1:Go IoT 开发平台的架构演进与生态蓝图
直播时间 2025-03-05 14:35:37

国产工作流引擎 终结「996」开发困局!
直播时间 2025-02-25 14:38:13

免费开源宝藏 ShopXO,电商系统搭建秘籍大公开!
直播时间 2025-02-18 14:31:04

从数据孤岛到数据智能 - 企业级数据管理利器深度解析
所有评论(0)