Home > Net >  New request guidance, found a method, indicate the shape, but do not need to preach, that T have a p
New request guidance, found a method, indicate the shape, but do not need to preach, that T have a p

Time:05-22

The code is as follows:
 public static string OutNull () 
{
JObject outjob=new JObject ();
JObject job=new JObject ();
JArray List=new JArray ();
If (typeof (T)==typeof (JArray))
Outjob. Add (new JProperty (" list ", a list));
Else if (typeof (T)==typeof (JObject))
Outjob. Add (new JProperty (" data ", job));
Else if (typeof (T)==typeof (string))
Outjob. Add (new JProperty (" data ", ""));

Return JsonDo. JobjectToJson (outjob);
}

CodePudding user response:

Meaning is obvious, is to get generic types, and then according to the type definition Json structure

CodePudding user response:

You can also be defined as a public static string OutNull (Type, Type)

CodePudding user response:

You have the code under test to know,
The difference between passing in different types to see return result,

CodePudding user response:

Don't need to struggle, because no significance, this is a kind of helpless choice, normal is retrun new {data=https://bbs.csdn.net/topics/obj}

The back-end DDD, and the model, no matter what the outside his agreement

Then the front said to him, Lao zi won't play a collection of data and said that said said object, and a string of trying

So the back-end can only helpless, poking fun at the front, side to write such a rubbish things to deal with

CodePudding user response:

Avoid passing in different types of values to write multiple methods,
May have a look this, speak very clear
https://blog.csdn.net/kebi007/article/details/77800954

CodePudding user response:

Is necessary, the general is written for compatibility, it can effectively avoid duplicate code, wait you to code writes a certain height, you would think it's all very well to generics in some scenarios

CodePudding user response:

This is just a show, not a practical thing

A data for the front end, enough for the front end will write defensive data=https://bbs.csdn.net/topics/xxx | | d.d ata is basic, a not null, not deal with ", "won't deal with the front end of the [], the ans can directly drive off, I can do, you write so a garbage, BAT will do to you? You call BAT code, there is null, you let the BAT give you change??

CodePudding user response:

Json structure of return an empty, empty object
  •  Tags:  
  • C#
  • Related