Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert User class object to json file when success login ?

I need to convert user class object to json file represent status of login and data related as following ;

this is actually desired result
{

"request_status" : {

"status" : "succeeded",

"code": 0,

"message" : "login succeeded!"

},

"user_data": {

  "UserFullName" : "Admin",

  "LoginTime" : "12:00"

   

},

"branches": [

{

  "BranchCode" : "1",

  "BranchName":"Baha"

   

}

]

}


public class Users

    {

        public string UserName { get; set; }

        public string Password { get; set; }

        public string MessageStatus { get; set; }

        public int StatusCode { get; set; }

        public string StatusText { get; set; }

        public string IpAddress { get; set; }

        public string BrowserInfo { get; set; }

        public DataTable dtgetBranches { get; set; }

        public string LoginTime { get; set; }

    }


What I have tried:

What I try is :



[HttpPost(Contracts.ApiRoutes.Login.PostUserLogin)]

        public  IActionResult PostUserLogins(Users user)

        {

            int LoginStatus = _AuthunticateService.PostUserLogin(user.UserName,user.Password ,out DataTable Branches,out string errorMessage, out int statusCode);

            if(LoginStatus == 0)

            {

                user.StatusCode = statusCode;

                user.StatusText = "succeeded";

                user.MessageStatus = "login succeeded!";

                if (Branches.Rows.Count > 0)

                {

                    user.dtgetBranches = Branches;

                }

                user.LoginTime = DateTime.Now.ToString();

// How to convert user class after assign values to json result as script above diplay

            }

         }

How to convert user class object to json format as above ?
Posted
Updated 30-Aug-19 21:55pm

1 solution

 
Share this answer
 
Comments
ahmed_sa 31-Aug-19 6:52am    
all links not related to my topic i posted can you please any one help me
ahmed_sa 31-Aug-19 6:52am    
all links not related to my topic i posted can you please any one help me
Richard MacCutchan 31-Aug-19 7:38am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900