本文整理汇总了C#中LitJson.JsonData.SetJsonType方法的典型用法代码示例。如果您正苦于以下问题:C# JsonData.SetJsonType方法的具体用法?C# JsonData.SetJsonType怎么用?C# JsonData.SetJsonType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LitJson.JsonData
的用法示例。
在下文中一共展示了JsonData.SetJsonType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeJson
public static JsonData SerializeJson(OSD osd)
{
switch (osd.Type)
{
case OSDType.Boolean:
return new JsonData(osd.AsBoolean());
case OSDType.Integer:
return new JsonData(osd.AsInteger());
case OSDType.Real:
return new JsonData(osd.AsReal());
case OSDType.String:
case OSDType.Date:
case OSDType.URI:
case OSDType.UUID:
return new JsonData(osd.AsString());
case OSDType.Binary:
byte[] binary = osd.AsBinary();
JsonData jsonbinarray = new JsonData();
jsonbinarray.SetJsonType(JsonType.Array);
for (int i = 0; i < binary.Length; i++)
jsonbinarray.Add(new JsonData(binary[i]));
return jsonbinarray;
case OSDType.Array:
JsonData jsonarray = new JsonData();
jsonarray.SetJsonType(JsonType.Array);
OSDArray array = (OSDArray)osd;
for (int i = 0; i < array.Count; i++)
jsonarray.Add(SerializeJson(array[i]));
return jsonarray;
case OSDType.Map:
JsonData jsonmap = new JsonData();
jsonmap.SetJsonType(JsonType.Object);
OSDMap map = (OSDMap)osd;
foreach (KeyValuePair<string, OSD> kvp in map)
jsonmap[kvp.Key] = SerializeJson(kvp.Value);
return jsonmap;
case OSDType.Unknown:
default:
return new JsonData();
}
}
示例2: SerializeJsonNoDefaults
private static JsonData SerializeJsonNoDefaults(OSD osd)
{
switch (osd.Type)
{
case OSDType.Boolean:
bool b = osd.AsBoolean();
if (!b)
return null;
return new JsonData(b);
case OSDType.Integer:
int v = osd.AsInteger();
if (v == 0)
return null;
return new JsonData(v);
case OSDType.Real:
double d = osd.AsReal();
if (d == 0.0d)
return null;
return new JsonData(d);
case OSDType.String:
case OSDType.Date:
case OSDType.URI:
string str = osd.AsString();
if (String.IsNullOrEmpty(str))
return null;
return new JsonData(str);
case OSDType.UUID:
UUID uuid = osd.AsUUID();
if (uuid == UUID.Zero)
return null;
return new JsonData(uuid.ToString());
case OSDType.Binary:
byte[] binary = osd.AsBinary();
if (binary == Utils.EmptyBytes)
return null;
JsonData jsonbinarray = new JsonData();
jsonbinarray.SetJsonType(JsonType.Array);
for (int i = 0; i < binary.Length; i++)
jsonbinarray.Add(new JsonData(binary[i]));
return jsonbinarray;
case OSDType.Array:
JsonData jsonarray = new JsonData();
jsonarray.SetJsonType(JsonType.Array);
OSDArray array = (OSDArray)osd;
for (int i = 0; i < array.Count; i++)
jsonarray.Add(SerializeJson(array[i]));
return jsonarray;
case OSDType.Map:
JsonData jsonmap = new JsonData();
jsonmap.SetJsonType(JsonType.Object);
OSDMap map = (OSDMap)osd;
foreach (KeyValuePair<string, OSD> kvp in map)
{
JsonData data = SerializeJsonNoDefaults(kvp.Value);
if (data != null)
jsonmap[kvp.Key] = data;
}
return jsonmap;
case OSDType.Unknown:
default:
return null;
}
}
示例3: SerializeJson
public static JsonData SerializeJson(OSD osd)
{
switch (osd.Type)
{
case OSDType.Boolean:
return new JsonData(osd.AsBoolean());
case OSDType.Integer:
return new JsonData(osd.AsInteger());
case OSDType.Real:
return new JsonData(osd.AsReal());
case OSDType.String:
return new JsonData(osd.AsString());
case OSDType.Date:
return new JsonData("date::" + osd.AsString());
case OSDType.URI:
return new JsonData("uri::" + osd.AsString());
case OSDType.UUID:
return new JsonData("uuid::" + osd.AsString());
case OSDType.Binary:
return new JsonData("b64::" + Convert.ToBase64String(osd.AsBinary()));
case OSDType.Array:
JsonData jsonarray = new JsonData();
jsonarray.SetJsonType(JsonType.Array);
OSDArray array = (OSDArray)osd;
for (int i = 0; i < array.Count; i++)
jsonarray.Add(SerializeJson(array[i]));
return jsonarray;
case OSDType.Map:
JsonData jsonmap = new JsonData();
jsonmap.SetJsonType(JsonType.Object);
OSDMap map = (OSDMap)osd;
foreach (KeyValuePair<string, OSD> kvp in map)
jsonmap[kvp.Key] = SerializeJson(kvp.Value);
return jsonmap;
case OSDType.Unknown:
default:
return new JsonData();
}
}
示例4: 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);
}
示例5: StepMatches
string StepMatches(string stepName)
{
JsonData matches = new JsonData();
matches.SetJsonType(JsonType.Array);
foreach (var sd in _repository.StepDefinitions)
{
List<StepArgument> args = sd.ArgumentsFrom(stepName);
if(args != null)
{
JsonData stepMatch = new JsonData();
stepMatch["id"] = sd.Id;
JsonData jsonArgs = new JsonData();
jsonArgs.SetJsonType(JsonType.Array);
foreach (var arg in args)
{
JsonData jsonArg = new JsonData();
jsonArg["val"] = arg.Val;
jsonArg["pos"] = arg.Pos;
jsonArgs.Add(jsonArg);
}
stepMatch["args"] = jsonArgs;
matches.Add(stepMatch);
}
}
JsonData response = new JsonData();
response.Add("step_matches");
response.Add(matches);
return JsonMapper.ToJson(response);
}
示例6: 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;
}
示例7: InvInfoPacket
public SocketModel InvInfoPacket(InvInfoDTO data)
{
int playerID = data.playerID;
string playerUUID = data.playerUUID;
int type = data.type;//player = 1,Hero = 2,Guide = 3,Inv = 4
int returnCode = ReturnCode.Success;//设定返回代码
if (CheckUUID(playerUUID))
{
string returnData = "";
switch (type)
{
case 1://玩家页
{
JsonData json = new JsonData();
json.SetJsonType(JsonType.Array);//设置为数组
//从数据库中获取玩家所有的卡片的ID、类型、是否上场并添加到返回字符串
string command = string.Format("SELECT CardId,CardType,IsUsing FROM cardinventory WHERE CardOwnerId = '{0}'", playerID);
DataSet ds = MySQLHelper.GetDataSet(MySQLHelper.Conn, CommandType.Text, command, null);
foreach (DataRow row in ds.Tables[0].Rows)
{
JsonData rowJson = new JsonData();
rowJson["CardId"] = Convert.ToInt32(row["CardId"]);
rowJson["CardType"] = row["CardType"].ToString();
rowJson["IsUsing"] = Convert.ToBoolean(row["IsUsing"]);
json.Add(rowJson);
}
returnData = json.ToJson();
break;
}
case 2://英雄页
{
JsonData json = new JsonData();
json.SetJsonType(JsonType.Array);//设置为数组
//从数据库中获取玩家所有的英雄卡片的ID、是否上场并添加到返回字符串
string command = string.Format("SELECT CardId,IsUsing FROM cardinventory WHERE CardOwnerId = '{0}' AND CardType = '{1}'", playerID,"Character");
DataSet ds = MySQLHelper.GetDataSet(MySQLHelper.Conn, CommandType.Text, command, null);
foreach (DataRow row in ds.Tables[0].Rows)
{
JsonData rowJson = new JsonData();
rowJson["CardId"] = Convert.ToInt32(row["CardId"]);
rowJson["IsUsing"] = Convert.ToBoolean(row["IsUsing"]);
json.Add(rowJson);
}
returnData = json.ToJson();
break;
}
case 3://图鉴页
{
JsonData json = new JsonData();
json.SetJsonType(JsonType.Array);//设置为数组
//从数据库中获取玩家所有的英雄卡片的ID、是否上场并添加到返回字符串
string format = "SELECT *,COUNT(inv.CardId) AS OwnNum, " +
"MAX(inv.SpecialAttack + inv.SpecialEnergy+ inv.SpecialHealth+ inv.SpecialSpeed) AS Talent " +
"FROM cardinventory as inv " +
"LEFT JOIN card " +
"ON inv.CardId = card.CardId " +
"WHERE inv.CardOwnerId = {0} AND inv.CardType = {1}" +
"GROUP BY inv.CardId";
string command = string.Format(format, playerID, "Character");
DataSet ds = MySQLHelper.GetDataSet(MySQLHelper.Conn, CommandType.Text, command, null);
foreach (DataRow row in ds.Tables[0].Rows)
{
JsonData rowJson = new JsonData();
rowJson["CardId"] = Convert.ToInt32(row["CardId"]);
rowJson["CardName"] = Convert.ToString(row["CardName"]);
rowJson["OwnNum"] = Convert.ToInt32(row["OwnNum"]);
rowJson["MaxTalent"] = Convert.ToInt32(row["Talent"]);
rowJson["CardRarity"] = Convert.ToInt32(row["CardRarity"]);
rowJson["BaseHealth"] = Convert.ToInt32(row["BaseHealth"]);
rowJson["BaseEnergy"] = Convert.ToInt32(row["BaseEnergy"]);
rowJson["BaseAttack"] = Convert.ToInt32(row["BaseAttack"]);
rowJson["BaseSpeed"] = Convert.ToInt32(row["BaseSpeed"]);
rowJson["GrowHealth"] = Convert.ToInt32(row["GrowHealth"]);
rowJson["GrowEnergy"] = Convert.ToInt32(row["GrowEnergy"]);
rowJson["GrowAttack"] = Convert.ToInt32(row["GrowAttack"]);
rowJson["GrowSpeed"] = Convert.ToInt32(row["GrowSpeed"]);
json.Add(rowJson);
}
returnData = json.ToJson();
break;
}
case 4:
{
break;
}
default:
{
//.........这里部分代码省略.........