当前位置:网站首页>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
}]
}
边栏推荐
- 9.JNI_ Necessary optimization design
- Function simplification principle: save if you can
- Deep Learning with Pytorch-Train A Classifier
- Mmdet line by line deltaxywhbboxcoder
- Six implementation methods of singleton mode
- Electron, which can wrap web page programs into desktop applications
- [cmake] make command cannot be executed normally
- Get to know handler again
- Experience of an acmer
- Talking about kotlin process exception handling mechanism
猜你喜欢
Handwriting sorter component
What kind of experience is it to develop a "grandson" who will call himself "Grandpa"?
Duplicate entry '2' for key 'primary appears in JPA‘
Flutter 0001, environment configuration
Opencv learning notes-day6-7 (scroll bar operation demonstration is used to adjust image brightness and contrast, and createtrackbar() creates a scroll bar function)
桂林 穩健醫療收購桂林乳膠100%股權 填補乳膠產品線空白
Explanation on the use of password profiteering cracking tool Hydra
MySQL-- Entity Framework Code First(EF Code First)
Idea shortcut key settings
Distributed ID
随机推荐
Esp32 (7): I2S and I2C drivers for function development
7. know JNI and NDK
2021-10-20
Talk about the kotlin cooperation process and the difference between job and supervisorjob
Rew acoustic test (I): microphone calibration
Acquisition de 100% des actions de Guilin latex par Guilin Robust Medical pour combler le vide de la gamme de produits Latex
Opencv learning notes -day4 image pixel reading and writing operations (array traversal and pointer traversal implementation, uchar vec3b data type and mat class functions mat:: at(), mat:: ptr())
[shutter] solve failed assertion: line 5142 POS 12: '_ debugLocked‘: is not true.
Pipe pipe --namedpipe and anonymouspipe
Talking about kotlin process exception handling mechanism
Niuke IOI weekly competition 20 popularization group (problem solving)
4. use ibinder interface flexibly for short-range communication
Esp32 (6): Bluetooth and WiFi functions for function development
[cmake] make command cannot be executed normally
Express file upload
5. Messager framework and imessager interface
Design specification for smart speakers v1.0
2020-11-02
Opencv learning notes -day 11 (split() channel separation function and merge() channel merge function)
Simple redis lock