当前位置:网站首页>Returnjson, which allows more custom data or class names to be returned
Returnjson, which allows more custom data or class names to be returned
2022-06-30 09:46:00 【Xiaosheng one】
ReturnJson, Let's go back Json More custom data or class names
After the background code is processed , Some required fields cannot be displayed , I'm here through ReturnJson To achieve , Let's start with the code before processing
[{
"ID": "1",
"Name": " First of all ",
"Sort": 1
}, {
"ID": "2",
"Name": " second ",
"Sort": 2
}]
But I need to add some fields to the outer layer , for example rowcount,errorMsg,success etc. , Lower upper process
//ReturnJson class , Used to add custom fields ,Data Class is the normal data , For example, the return data above
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; }
}
// This is the interface normally called , Is punctuated with ReturnJson Specific adding method of
public void GetData()
{
// Return the data
List<Data> Info= new List<Data>();
strint sql = "select * from Data";
// I have omitted the specific process in the middle ,helper Connect to database
using (MySqlHelper helper = new MySqlHelper(conStrBase))
{
DataSet ds = helper.ExecuteDataSet(sql , CommandType.Text);
info = DataTableToModelList<Data>(ds.Tables[0]);
}
// to list Set add data
ReturnJsonVd = new ReturnJson
{
rowcount = Info.Count,
errorMsg = "",
success = true,
rows = Info
};
jsonResult = JsonConvert.SerializeObject(Vd);
}
Above is the process of processing , It's like creating a class , Include fixed data
The following is the returned data after processing
{
"rowcount": 2,
"errorMsg": "",
"success": true,
"rows": [{
"ID": "1",
"Name": " First of all ",
"Sort": 1
}, {
"ID": "2",
"Name": " second ",
"Sort": 2
}]
}
边栏推荐
- Solution to pychart's failure in importing torch package
- 机器学习笔记 九:预测模型优化(防止欠拟合和过拟合问题发生)
- JVM family
- Redis docker 主从模式与哨兵sentinel
- Xlnet (generalized autorefressive trainingfor language understanding) paper notes
- Applet learning path 2 - event binding
- Idea setting automatic package Guide
- 【Ubuntu-MySQL8安装与主从复制】
- 布隆过滤器
- thrift简单使用
猜你喜欢
【新书推荐】Deno Web Development
Machine learning note 9: prediction model optimization (to prevent under fitting and over fitting problems)
近期学习遇到的比较问题
GPT (improving language understanding generative pre training) paper notes
CentOS MySQL installation details
Express - static resource request
Idea setting automatic package Guide
7. know JNI and NDK
桂林 稳健医疗收购桂林乳胶100%股权 填补乳胶产品线空白
桂林 穩健醫療收購桂林乳膠100%股權 填補乳膠產品線空白
随机推荐
Guilin robust medical acquired 100% equity of Guilin Latex to fill the blank of latex product line
Distributed session
QR code generation and analysis
【新书推荐】Deno Web Development
Create thread pool demo
Express - static resource request
MySQL internal component structure
Bloom filter
机器学习笔记 九:预测模型优化(防止欠拟合和过拟合问题发生)
Simple redis lock
Using OpenCV Net for image restoration
Pytorch for former Torch users - Tensors
1, 基本配置
训练一个图像分类器demo in PyTorch【学习笔记】
JWT expiration processing - single token scheme
Mysq database remote connection error, remote connection is not allowed
Express の post request
Thrift easy to use
Niuke rearrangement rule taking method
ACM intensive training graph theory exercise 3 in the summer vacation of 2020 [problem solving]