This is a unique good type, a good type that you can't put up with, OK, don't rip, directly on the dry.
I believe we all know that the return of JSON data when invoking an interface has become an unwritten standard, because of its fast parsing, easy to read and other excellent features, so the vast majority of the program apes love.
Let's introduce a return type that you might ignore or not know about today Jsonmessage
1 /// <summary>2 ///return Message3 /// </summary>4 Public classJsonmessage5 {6 /// <summary>7 ///is successful8 /// </summary>9 Public BOOLSuccess {Get;Set; }Ten /// <summary> One ///result Encoding A /// </summary> - Public stringCode {Get;Set; } - /// <summary> the ///Result Message - /// </summary> - Public stringMessage {Get;Set; } - + Public Override stringToString () - { + returnJsonhelper.tojson ( This); A } at}
The above is the whole code of Jsonmessage, so we can see that you do not have to bother to consider what parameters I should use to set my return information, this has prepared a unified and comprehensive parameter return value.
Direct on Demo
1 /// <summary>2 ///Demo3 /// </summary>4 /// <returns>JSON-formatted information</returns>5 [HttpPost]6[Route ("Api/login/demo")]7 Publicjsonmessage Demo ()8 {9Jsonmessage jmtemp =Newjsonmessage ();Ten Try One { AJmtemp.code =" $"; -Jmtemp.message ="Demo Success"; -Jmtemp.success =true; the}Catch(Exception ex) - { -Jmtemp.code ="201"; -Jmtemp.message ="Demo failed"; +Jmtemp.success =false; - } + returnjmtemp; A}
Let's see how the show works.
This is the end, isn't it simple
==================================================
Reward him:
[Experience sharing] Application of return type Jsonmessage in Webapi