REST API-如何使用C#获取JSON API请求调用并发送JSON响应? [英] Rest API- how to get json API request call and send json response using C#?

查看:566
本文介绍了REST API-如何使用C#获取JSON API请求调用并发送JSON响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是

1.创建API以从其他系统获取用户信息(如下所示的JSON请求),并将这些信息更新到数据库.
2.更新后要发回JSON响应(模型如下).


我正在使用实体框架模型.我想构建满足上述要求的API,请帮助我

我的控制器:

namespace CT.API.User
{
    public class UserController : CTControllerBase
    {
        //API
        [AllowAnonymous]
        public JsonResult USerApiTest()
        {
            // to handle the code
       }
    }
}


请求详细信息:

 {"REQLEN":4,"REQDTL":[{"ID":"48490","UserName":"Test1","Password":"Test1"}},{"ID" :"48491","UserName":"Test2","Password":"Test2"}]} 


回复详细信息:

 {"RESLEN":4,"RESDTL":[{"ID":"48490","Status":"Success"}},{"ID":"48491","Status" :失败"}]} 



我尝试过的事情:

我是API的新手,并且想要构建满足上述要求的API,请使用以下代码帮助我:

解决方案

对于像这样的初学者来说,这里是一个好地方您开始: ASP.NET Web API | ASP.NET网站 [ ^ ]

My requirements are

1.create API to get the user information(JSON request as given in below) from other system, update those information to database.
2.After update want to send the JSON response(model is given below) back.


I''m using entity framework model. I want to build the API to meet the mentioned requirements, please help me

My controller:

namespace CT.API.User
{
    public class UserController : CTControllerBase
    {
        //API
        [AllowAnonymous]
        public JsonResult USerApiTest()
        {
            // to handle the code
       }
    }
}


Request Details:

{"REQLEN":4,"REQDTL":[{"ID":"48490","UserName":"Test1","Password":"Test1"},{"ID":"48491","UserName":"Test2","Password":"Test2"}]}


Reponse Details:

{"RESLEN":4,"RESDTL":[{"ID":"48490","Status":"Success"},{"ID":"48491","Status":"Fail"}]}



What I have tried:

I''m new to API and want to build the API to meet the mentioned requirements, please help me with the code

解决方案

Here is a good place for beginners like you to start: Getting Started with ASP.NET Web API 2 (C#) | Microsoft Docs[^] and here: ASP.NET Web API | The ASP.NET Site[^]


这篇关于REST API-如何使用C#获取JSON API请求调用并发送JSON响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆