当前位置:网站首页>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
}]
}
边栏推荐
- [shutter] solve failed assertion: line 5142 POS 12: '_ debugLocked‘: is not true.
- Experience of an acmer
- Raspberry pie 4B no screen installation system and networking using VNC wireless projection function
- Rew acoustic test (III): generate test signal
- Find the number that appears only once in the array
- Express file upload
- Influencing factors of echo cancellation for smart speakers
- Opencv learning notes -day 11 (split() channel separation function and merge() channel merge function)
- Acquisition de 100% des actions de Guilin latex par Guilin Robust Medical pour combler le vide de la gamme de produits Latex
- So the toolbar can still be used like this? The toolbar uses the most complete parsing. Netizen: finally, you don't have to always customize the title bar!
猜你喜欢

Handwriting sorter component

I once met a girl whom I most wanted to take care of all my life. Later... No later

Opencv learning notes -day2 (implemented by the color space conversion function cvtcolar(), and imwrite image saving function imwrite())

float

Linear-gradient()

Opencv learning notes -day10 logical operation of image pixels (usage of rectangle function and rect function and bit related operation in openCV)

Esp32 things (3): overview of the overall system design
![[wechat applet] realize applet pull-down refresh and pull-up loading](/img/23/2668a3a36fd46f63732c753fd6f237.jpg)
[wechat applet] realize applet pull-down refresh and pull-up loading

Rew acoustic test (III): generate test signal

The elegant combination of walle and Jianbao
随机推荐
Tutorial for beginners of small programs day01
Torchvision loads the weight of RESNET except the full connection layer
Demo of guavacache
So the toolbar can still be used like this? The toolbar uses the most complete parsing. Netizen: finally, you don't have to always customize the title bar!
Deep Learning with Pytorch- A 60 Minute Blitz
Reading notes of "Introduction to deep learning: pytoch"
Pipe pipe --namedpipe and anonymouspipe
Talking about kotlin process exception handling mechanism
Pytorch for former Torch users - Tensors
float
桂林 稳健医疗收购桂林乳胶100%股权 填补乳胶产品线空白
Flutter theme (skin) changes
Talk about the kotlin cooperation process and the difference between job and supervisorjob
Raspberry pie 4B no screen installation system and networking using VNC wireless projection function
Design specification for smart speakers v1.0
Rew acoustic test (VI): signal and measurement
asdsadadsad
Opencv learning notes -day1 (image reading display imread, imshow, namedwindow)
2021-10-20
Find the number that appears only once in the array