当前位置:网站首页>ReturnJson,让返回数据多一些自定义数据或类名
ReturnJson,让返回数据多一些自定义数据或类名
2022-06-30 09:32:00 【小生一枚】
ReturnJson,让返回的Json数据多一些自定义数据或类名
后台代码通过处理后,有些需要的字段无法展示,我这里通过ReturnJson来实现,先上没处理前的代码
[{
"ID": "1",
"Name": "第一",
"Sort": 1
}, {
"ID": "2",
"Name": "第二",
"Sort": 2
}]
但是我需要外层增加一些字段,例如rowcount,errorMsg,success等,下边上处理过程
//ReturnJson类,用来增加自定义字段,Data类是正常拿的数据,例如上边的返回数据
public class ReturnJson
{
public string errorMsg {
get; set; }
public int rowcount {
get; set; }
public bool success{
get; set; }
public List<Data> rows {
get; set; }
}
public class Data
{
public string ID{
get; set; }
public string Name{
get; set; }
public int Sort{
get; set; }
}
//这个就是正常被调用的接口,里边有ReturnJson的具体添加方法
public void GetData()
{
//返回数据
List<Data> Info= new List<Data>();
strint sql = "select * from Data";
//中间的具体过程我省略了,helper为数据库连接
using (MySqlHelper helper = new MySqlHelper(conStrBase))
{
DataSet ds = helper.ExecuteDataSet(sql , CommandType.Text);
info = DataTableToModelList<Data>(ds.Tables[0]);
}
//给list集合添加数据
ReturnJsonVd = new ReturnJson
{
rowcount = Info.Count,
errorMsg = "",
success = true,
rows = Info
};
jsonResult = JsonConvert.SerializeObject(Vd);
}
上边就是处理的过程,相当于创建了一个类,把固定数据给包含进去
下边是处理后的返回数据
{
"rowcount": 2,
"errorMsg": "",
"success": true,
"rows": [{
"ID": "1",
"Name": "第一",
"Sort": 1
}, {
"ID": "2",
"Name": "第二",
"Sort": 2
}]
}
边栏推荐
- Dart asynchronous task
- Raspberry pie 4B no screen installation system and networking using VNC wireless projection function
- Clickhouse installation (quick start)
- Talk about the job experience of kotlin cooperation process
- Talk about writing
- Invalid update: invalid number of sections. The number of sections contained in the table view after
- Deep Learning with Pytorch- neural network
- Function simplification principle: save if you can
- I once met a girl whom I most wanted to take care of all my life. Later... No later
- Installation, use and explanation of vulnerability scanning tool OpenVAS
猜你喜欢

Harmonyos actual combat - ten thousand words long article understanding service card development process

Rew acoustic test (VI): signal and measurement

Properties of string

What kind of experience is it to develop a "grandson" who will call himself "Grandpa"?

float

Summary of Android knowledge points and common interview questions

Using appbarlayout to realize secondary ceiling function

ES6 learning path (II) let & const

5. Messager framework and imessager interface

Challenge transform() 2D
随机推荐
7. know JNI and NDK
Dart asynchronous task
Demo of guavacache
Initialize static resource demo
Niuke rearrangement rule taking method
Resnet50+fpn for mmdet line by line code interpretation
Distributed ID
Tclistener server and tcpclient client
[shutter] solve failed assertion: line 5142 POS 12: '_ debugLocked‘: is not true.
Rew acoustic test (I): microphone calibration
Deep Learning with Pytorch- A 60 Minute Blitz
Acquisition de 100% des actions de Guilin latex par Guilin Robust Medical pour combler le vide de la gamme de produits Latex
Deep Learning with Pytorch-Train A Classifier
Esp32 things (V): analysis of common API of esp32 of Swiss Army knife
Opencv learning notes -day8 (keyboard typing (waitkey()); Wait for typing) action: triggers some action when the appropriate character is typed using the keyboard)
Enum demo
ES6 learning path (II) let & const
2021-10-20
Dart basic notes
[protobuf] protobuf generates cc/h file through proto file