v1.1.2
This commit is contained in:
@@ -4,9 +4,21 @@ namespace CC.Yi.Common
|
||||
{
|
||||
public static class JsonHelper
|
||||
{
|
||||
public static string JsonToString(object q)
|
||||
public static string JsonToString(object data=null, int code = 200, bool flag = true, string message = "成功")
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(q);
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { code = code, flag = flag, message = message, data = data });
|
||||
}
|
||||
public static string JsonToString2(object data = null, int code = 200, bool flag = true, string message = "成功",int count=0)
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { code = code, flag = flag, message = message, count=count,data = data });
|
||||
}
|
||||
public static string ToString(object data)
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(data);
|
||||
}
|
||||
public static T ToJson<T>(string data)
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
40
CC.Yi.Common/Result.cs
Normal file
40
CC.Yi.Common/Result.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Common
|
||||
{
|
||||
/// <summary>
|
||||
/// 结果数据
|
||||
/// </summary>
|
||||
public class Result
|
||||
{
|
||||
public bool Status { get; set; }
|
||||
public int Code { get; set; }
|
||||
public string Msg { get; set; }
|
||||
public object Data { get; set; }
|
||||
public static Result Instance(bool status, string msg)
|
||||
{
|
||||
return new Result() { Status = status,Code=500, Msg = msg };
|
||||
}
|
||||
public static Result Error(string msg)
|
||||
{
|
||||
return new Result() { Status = false, Code = 500, Msg = msg };
|
||||
}
|
||||
public static Result Success(string msg= "succeed")
|
||||
{
|
||||
return new Result() { Status = true, Code = 200, Msg = msg };
|
||||
}
|
||||
public Result SetData(object obj)
|
||||
{
|
||||
this.Data = obj;
|
||||
return this;
|
||||
}
|
||||
public Result SetCode(int Code)
|
||||
{
|
||||
this.Code = Code;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user