本文整理汇总了C#中LitJson.JsonData.Add方法的典型用法代码示例。如果您正苦于以下问题:C# JsonData.Add方法的具体用法?C# JsonData.Add怎么用?C# JsonData.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LitJson.JsonData
的用法示例。
在下文中一共展示了JsonData.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddColour
static JsonData AddColour(JsonData data, Color c)
{
data.Add((int)c.R);
data.Add((int)c.G);
data.Add((int)c.B);
return data;
}
示例2: AsArrayTest
public void AsArrayTest ()
{
JsonData data = new JsonData ();
data.Add (1);
data.Add (2);
data.Add (3);
data.Add ("Launch!");
Assert.IsTrue (data.IsArray, "A1");
Assert.AreEqual ("[1,2,3,\"Launch!\"]", data.ToJson (), "A2");
}
示例3: LoopChildren
/// <summary>
/// Loops the children.
/// </summary>
/// <returns>The children.</returns>
/// <param name="t">T.</param>
private static JsonData LoopChildren(Transform t)
{
RectTransform rt = (RectTransform)t;
JsonData jd = new JsonData ();
jd ["name"] = t.name;
JsonData trJD = new JsonData ();
trJD ["position"] = rt.anchoredPosition.VectorToJson ();
trJD ["sizeDelta"] = rt.sizeDelta.VectorToJson ();
trJD ["anchorMin"] = rt.anchorMin.VectorToJson ();
trJD ["anchorMax"] = rt.anchorMax.VectorToJson ();
trJD ["pivot"] = rt.pivot.VectorToJson ();
trJD ["rotation"] = rt.rotation.eulerAngles.VectorToJson ();
trJD ["scale"] = rt.localScale.VectorToJson ();
jd ["transform"] = trJD;
int len = t.childCount;
JsonData ch = new JsonData ();
for (int i = 0; i < len; ++i) {
ch.Add(LoopChildren (t.GetChild (i)));
}
string jsStr = JsonMapper.ToJson (ch);
jd ["children"] = string.IsNullOrEmpty(jsStr)?"[]":ch;
return jd;
}
示例4: IntArrayToString
public static string IntArrayToString(int[] array)
{
JsonData data = new JsonData();
foreach (int a in array)
{
data.Add(a);
}
return data.ToJson();
}
示例5: ProcessRequest
public void ProcessRequest(HttpContext context)
{
int total = 0;
JsonData rows = new JsonData();
if (context.Request.Cookies["SyglAdmin"] == null)
{
context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
context.Response.Write("未登录或登录超时!请重新登陆!");
context.Response.End();
}
else
{
string connStr = ConfigurationManager.ConnectionStrings["SyglConnStr"].ConnectionString;
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = connStr;
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "select ptmID,ptmName from ptms_tb order by ptmID";
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
do
{
JsonData row = new JsonData();
row["ptmName"] = dr["ptmName"].ToString();
row["ptmID"] = Convert.ToInt32(dr["ptmID"].ToString());
rows.Add(row);
} while (dr.Read());
}
//查询数量
cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "select count(ptmID) from ptms_tb ";
total = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close();
JsonData jsonData = new JsonData();
jsonData["total"] = total;
jsonData["rows"] = rows;
string echoString = jsonData.ToJson();
context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
context.Response.Write(echoString);
context.Response.End();
}
}
示例6: WriteJson
//write json
public void WriteJson( JsonData parent )
{
JsonData json = new JsonData();
json["name"] = this.m_strName;
if(this.m_cRoot != null )
{
json["node"] = new JsonData();
json["node"].SetJsonType(JsonType.Object);
json["node"] = this.m_cRoot.WriteJson();
}
parent.Add(json);
}
示例7: ProcessRequest
/* 返回json格式
* id:节点id,对载入远程数据很重要。
text:显示在节点的文本。
state:节点状态,'open' or 'closed',默认为'open'。当设置为'closed'时,拥有子节点的节点将会从远程站点载入它们。
checked:表明节点是否被选择。
attributes:可以为节点添加的自定义属性。
children:子节点,必须用数组定义。
*/
public void ProcessRequest(HttpContext context)
{
//查询数据库获取实验室列表
DataModel dm=new DataModel();
JsonData jd = new JsonData();
List<LabType> lts = dm.GetLabTypes();
List<LabChType> lcts = dm.GetLabChTypes();
List<Lab> labs = dm.GetLabs();
foreach (var t in lts)
{
JsonData jt = new JsonData();
jt["id"] = t.LabTypeID;
jt["text"] = t.LabTypeName;
jt["iconCls"] = "icon-application_cascade";
jt["children"] = new JsonData();
foreach (var ct in lcts.FindAll(delegate(LabChType lct) { return lct.LabSupType == t.LabTypeID; }))
{
JsonData jct = new JsonData();
jct["id"] = ct.LabChID;
jct["text"] = ct.LabChName;
jct["iconCls"] = "icon-application_cascade";
jct["children"] = new JsonData();
foreach (var lb in labs.FindAll(delegate(Lab _lb) { return _lb.LabType == ct.LabChID; }))
{
JsonData jLab = new JsonData();
jLab["id"] = lb.LabID;
jLab["text"] =lb.LabName;
//"iconCls":"icon-search"
jLab["iconCls"] = "icon-application_home";
jLab["checked"] = lb.LabDefault;
jct["children"].Add(jLab);
}
jt["children"].Add(jct);
}
jd.Add(jt);
}
string labStr=jd.ToJson();
context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
context.Response.Write(labStr);
context.Response.End();
}
示例8: GetJsonString
// Utility function that takes a list of SemanticObject's evaluated as
// having a relationship with the given object and outputs as a JSON object
public virtual JsonData GetJsonString(List<SemanticObject> affectedNodes)
{
if (NetMessenger.logTimingInfo)
Debug.LogFormat("Get Json for relationship {1}, {0}", Utils.GetTimeStamp(), name);
JsonData retClass = new JsonData(JsonType.Object);
Dictionary<SemanticObject, List<SemanticObject>> relationMap;
Evaluate(affectedNodes, out relationMap);
if (NetMessenger.logTimingInfo)
Debug.LogFormat(" Finished evaluate relationships {0}", Utils.GetTimeStamp());
foreach(SemanticObject obj in relationMap.Keys)
{
JsonData lst = new JsonData(JsonType.Array);
foreach(SemanticObject entry in relationMap[obj])
lst.Add(entry.identifier);
retClass[obj.identifier] = lst;
}
if (NetMessenger.logTimingInfo)
Debug.LogFormat(" Finished creating relationships json map {0} with {1} keys", Utils.GetTimeStamp(), relationMap.Keys.Count);
return retClass;
}
示例9: ProcessRequest
public void ProcessRequest(HttpContext context)
{
OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["SyglConnStr"].ConnectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from imgs_tb order by imgID";
OleDbDataReader dr = cmd.ExecuteReader();
string echoString="";
JsonData rows = new JsonData();
int total = 0;
if (dr.Read())
{
do
{
total++;
JsonData jsonDataItem = new JsonData();
jsonDataItem["imgID"] = Convert.ToInt32( dr["imgID"].ToString());
jsonDataItem["imgFile"] = dr["imgFile"].ToString();
jsonDataItem["imgLink"] = dr["imgLink"].ToString();
rows.Add(jsonDataItem);
} while (dr.Read());
}
else
{
rows = "";
}
JsonData jsonData = new JsonData();
jsonData["total"] = total;
jsonData["rows"] = rows;
echoString = jsonData.ToJson();
context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
context.Response.Write(echoString);
context.Response.End();
}
示例10: ProcessRequest
/* 返回json格式
* id:节点id,对载入远程数据很重要。
text:显示在节点的文本。
state:节点状态,'open' or 'closed',默认为'open'。当设置为'closed'时,拥有子节点的节点将会从远程站点载入它们。
checked:表明节点是否被选择。
attributes:可以为节点添加的自定义属性。
children:子节点,必须用数组定义。
*/
public void ProcessRequest(HttpContext context)
{
//查询数据库获取实验室列表
LxyOledb oledb = new LxyOledb();
oledb.Conn.Open();
oledb.Cmd.CommandText = "select * from Term_tb order by TermStartDay desc";
oledb.Dr = oledb.Cmd.ExecuteReader();
JsonData jd = new JsonData();
while(oledb.Dr.Read()){
JsonData jdWeek = new JsonData();
jdWeek["id"] = Convert.ToInt32(oledb.Dr["TermID"]);
jdWeek["text"] = oledb.Dr["TermName"].ToString();
jdWeek["TermStartDay"] = ((DateTime)oledb.Dr["TermStartDay"]).ToString("yyyy-MM-dd");
jdWeek["TermWeeks"] = Convert.ToInt32(oledb.Dr["TermWeeks"]);
jdWeek["iconCls"] = "icon-date";
jdWeek["isCurrent"] = oledb.Dr["TermIsCurrent"].ToString();
jd.Add(jdWeek);
}
string jdString = jd.ToJson();
context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
context.Response.Write(jdString);
context.Response.End();
}
示例11: ProcessRequest
public void ProcessRequest(HttpContext context)
{
int total = 0;
JsonData rows = new JsonData();
if (context.Request.Cookies["SyglAdmin"] == null)
{
context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
context.Response.Write("未登录或登录超时!请重新登陆!");
context.Response.End();
}
else
{
int clm = Convert.ToInt32(context.Request["clm"]);
int page = 0;
if (context.Request["page"] != null && context.Request["page"] != "")
{
page = Convert.ToInt32(context.Request["page"]) - 1;
}
int pageSize = 10;
if (context.Request["rows"] != null && context.Request["rows"] != "")
{
pageSize = Convert.ToInt32(context.Request["rows"]);
}
string sort = "articlePostTime";
if (context.Request["sort"] != null && context.Request["sort"] != "")
{
sort = (context.Request["sort"]);
}
string order = "desc";
if (context.Request["order"] != null && context.Request["order"] != "")
{
order = (context.Request["order"]);
}
string connStr = ConfigurationManager.ConnectionStrings["SyglConnStr"].ConnectionString;
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = connStr;
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
if (page == 0)
{
cmd.CommandText = "select top " + pageSize
+ " articleID,articleTitle,articlePostTime from articles_tb where articleType = @type1 order by " + sort + " " + order + " ";
// cmd.CommandText = "select top " + pageSize +
// " articleID,articleTitle,articlePostTime from articles_tb where clm [email protected] order by articlePostTime desc )";
cmd.Parameters.AddWithValue("@type1", clm);
}
else
{
cmd.CommandText = "select top " + pageSize +
" articleID,articleTitle,articlePostTime from articles_tb where clm [email protected] and articleID not in ( select top " + page * pageSize +
" articleID from articles_tb order by order by " + sort + " " + order + " ) order by " + sort + " " + order + " )";
cmd.Parameters.AddWithValue("@clm", clm);
cmd.Parameters.AddWithValue("@sort", sort);
cmd.Parameters.AddWithValue("@order", order);
cmd.Parameters.AddWithValue("@sort_", sort);
cmd.Parameters.AddWithValue("@order_", order);
}
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
do
{
JsonData row = new JsonData();
row["articleTitle"] = dr["articleTitle"].ToString();
row["articlePostTime"] = ((DateTime)dr["articlePostTime"]).ToString("yyyy年MM月dd日");
row["articleID"] = Convert.ToInt32(dr["articleID"].ToString());
rows.Add(row);
} while (dr.Read());
}
else
{
rows = "";
}
//查询数量
cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "select count(articleID) from articles_tb where [email protected] ";
cmd.Parameters.AddWithValue("@clm", clm);
total = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close();
JsonData jsonData = new JsonData();
jsonData["total"] = total;
jsonData["rows"] = rows;
string echoString = jsonData.ToJson();
context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
context.Response.Write(echoString);
context.Response.End();
}
}
示例12: CreateInvokeRequest
static string CreateInvokeRequest(string id, params string[] invokeArgs)
{
JsonData req = new JsonData();
req.Add("invoke");
JsonData parameters = new JsonData();
parameters["id"] = id;
JsonData args = new JsonData();
args.SetJsonType(JsonType.Array); // To avoid invalid json if it is empty
foreach(var arg in invokeArgs) {
args.Add(arg);
}
parameters["args"] = args;
req.Add(parameters);
return JsonMapper.ToJson(req);
}
示例13: ProcessRequest
public void ProcessRequest(HttpContext context)
{
int total = 0;
JsonData rows = new JsonData();
if (context.Session["adminID"] == null)
{
context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
context.Response.Write("未登录或登录超时!请重新登陆!");
context.Response.End();
}
else
{
int y = DateTime.Now.Year;
int m = DateTime.Now.Month;
if (context.Request.Params["y"] == "" || context.Request.Params["y"] == null)
{
}
else
{
y = Convert.ToInt32(context.Request.Params["y"]);
}
if (context.Request.Params["y"] == "" || context.Request.Params["y"] == null)
{
}
else
{
m = Convert.ToInt32(context.Request.Params["m"]);
}
int page = 0;
if (context.Request["page"] != null && context.Request["page"] != "")
{
page = Convert.ToInt32(context.Request["page"]) - 1;
}
int pageSize = 15;
if (context.Request["rows"] != null && context.Request["rows"] != "")
{
pageSize = Convert.ToInt32(context.Request["rows"]);
}
string sort = "wkEntryTime";
if (context.Request["sort"] != null && context.Request["sort"] != "")
{
sort = (context.Request["sort"]);
}
string order = "asc";
if (context.Request["order"] != null && context.Request["order"] != "")
{
order = (context.Request["order"]);
}
LNSql lnSql = new LNSql();
lnSql.conn.Open();
if (page == 0)
{
lnSql.cmd.CommandText = "select top " + pageSize
+ " * FROM workers_tb order by " + sort + " " + order + " ";
}
else
{
lnSql.cmd.CommandText = "select top " + pageSize +
" * FROM workers_tb where wkID not in ( select top " + page * pageSize +
" wkID from from workers_tb order by order by " + sort + " " + order + " ) order by " + sort + " " + order + " )";
}
lnSql.da.SelectCommand = lnSql.cmd;
lnSql.da.Fill(lnSql.ds,"workers_tb");
//wkID字符串
string wstr = "0";
if (lnSql.ds.Tables["workers_tb"].Rows.Count > 0)
{
foreach (DataRow dr in lnSql.ds.Tables["workers_tb"].Rows)
{
wstr+=","+dr["wkID"].ToString();
}
//查询缺勤情况
lnSql.cmd.CommandText = "select * from unworks_tb where uworker in ("+wstr+") and uwkYear = "+y+" and uwkMonth = "+ m+" ";
lnSql.da.SelectCommand = lnSql.cmd;
lnSql.da.Fill(lnSql.ds,"uwks_tb");
//查询加班情况
lnSql.cmd.CommandText = "select * from overworks_tb where oworker in (" + wstr + ") and owkYear = " + y + " and owkMonth = " + m + " ";
lnSql.da.SelectCommand = lnSql.cmd;
lnSql.da.Fill(lnSql.ds, "owks_tb");
//转化为字符串
foreach (DataRow dr in lnSql.ds.Tables["workers_tb"].Rows)
{
JsonData row = new JsonData();
row["wkID"] = dr["wkID"].ToString();
row["wkName"] = dr["wkName"].ToString();
row["wkPosition"] = dr["wkPosition"].ToString();
row["wkYear"] = y;
row["wkMonth"] = m;
//缺勤
//.........这里部分代码省略.........
示例14: ToJson
private JsonData ToJson(Bundle bundle)
{
JsonData target = new JsonData();
if (bundle.Type == DataType.Object) {
target.SetJsonType(JsonType.Object);
foreach (KeyValuePair<string, Bundle> entry in bundle.Dictionary) {
switch (entry.Value.Type) {
case DataType.Boolean: target[entry.Key] = entry.Value.AsBool(); break;
case DataType.Integer: target[entry.Key] = entry.Value.AsLong(); break;
case DataType.Double: target[entry.Key] = entry.Value.AsDouble(); break;
case DataType.String: target[entry.Key] = entry.Value.AsString(); break;
default: target[entry.Key] = ToJson(entry.Value); break;
}
}
}
else {
target.SetJsonType(JsonType.Array);
foreach (Bundle entry in bundle.Array) {
switch (entry.Type) {
case DataType.Boolean: target.Add(entry.AsBool()); break;
case DataType.Integer: target.Add(entry.AsInt()); break;
case DataType.Double: target.Add(entry.AsDouble()); break;
case DataType.String: target.Add(entry.AsString()); break;
default: target.Add(ToJson(entry)); break;
}
}
}
return target;
}
示例15: GetKeysInvalidTypeTest
public void GetKeysInvalidTypeTest ()
{
JsonData data = new JsonData ();
data.Add (42); // turns it into an array
// .. but an array doesn't have keys
ICollection<string> keys = data.Keys;
Assert.IsNotNull (keys);
}