本文整理汇总了C#中JsonData类的典型用法代码示例。如果您正苦于以下问题:C# JsonData类的具体用法?C# JsonData怎么用?C# JsonData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonData类属于命名空间,在下文中一共展示了JsonData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItemsToFileJSon
private List<Item> ItemsToFileJSon(JsonData sourceData)
{
int LengthData = sourceData.Count;
List<Item> itemsToGetted = new List<Item>();
for (int i = 0; i < LengthData; i++)
{
Item itemGettedTmp = new Item()
{
Id = (int)sourceData[i]["Id"],
Name = sourceData[i]["Name"].ToString(),
Description = sourceData[i]["Description"].ToString(),
Intensity = (int)sourceData[i]["Intensity"],
TypeItem = (e_itemType)((int)sourceData[i]["Type"]),
ElementTarget = (e_element)((int)sourceData[i]["Element"]),
LevelRarity = (e_itemRarity)((int)sourceData[i]["Rarity"]),
IsStackable = (bool)sourceData[i]["Stackable"],
Sprite = Item.AssignResources(sourceData[i]["Sprite"].ToString())
};
itemsToGetted.Add(itemGettedTmp);
}
return itemsToGetted;
}
示例2: InitializeList
// 初始化部件列表, 同时初始化第一种部件类型的清单列表(包括图标和文字)
public void InitializeList(JsonData data)
{
ClearAll ();
JsonData jsonArray = data["data_list"];
for (int i = 0; i < jsonArray.Count; i++) {
GameObject item = GameObject.FindGameObjectWithTag("componentitem");
GameObject newItem = Instantiate(item) as GameObject;
newItem.GetComponent<ComponentItem>().componentId = (int)jsonArray[i]["id"];
newItem.GetComponent<ComponentItem>().componentName = jsonArray[i]["name"].ToString();
newItem.GetComponent<ComponentItem>().componentLabel.text = jsonArray[i]["name"].ToString();
newItem.GetComponent<ComponentItem>().name = jsonArray[i]["name"].ToString();
newItem.GetComponent<RectTransform>().localScale = Vector3.one;
newItem.transform.SetParent (gridLayout.transform);
newItem.GetComponent<RectTransform>().localScale = newItem.transform.parent.localScale;
componentItems.Add(newItem);
Color temp = newItem.GetComponent<ComponentItem>().triangle.color;
if (i == 0) {
temp.a = 255f;
} else {
temp.a = 0f;
}
newItem.GetComponent<ComponentItem>().triangle.color = temp;
newItem.SetActive (true);
}
SetContentWidth ();
if (jsonArray.Count > 0) {
WWWForm wwwForm = new WWWForm();
wwwForm.AddField("api_type", 3);
wwwForm.AddField("id", (int)jsonArray[0]["id"]);
GetComponent<HttpServer>().SendRequest(Constant.ReuestUrl, wwwForm, new HttpServer.GetJson(typeScrollView.InitializeList));
}
}
示例3: DoRequest
protected override void DoRequest(AjaxContext context, JsonData input, JsonData output)
{
// get...
AjaxValidator validator = new AjaxValidator();
string username = validator.GetRequiredString(input, "username");
string password = validator.GetRequiredString(input, "password");
// ok?
if (validator.IsOk)
{
// get...
User user = User.GetByUsername(context, username);
if (user != null)
{
// check...
if (user.CheckPassword(password))
{
// create an access token...
Token token = Token.CreateToken(context, user);
if (token == null)
throw new InvalidOperationException("'token' is null.");
// set...
output["token"] = token.TheToken;
}
else
validator.AddError("Password is invalid.");
}
else
validator.AddError("Username is invalid.");
}
// set...
validator.Apply(output);
}
示例4: ProcessRequest
public void ProcessRequest(HttpContext context)
{
string json = null;
using (Stream stream = context.Request.InputStream)
{
StreamReader reader = new StreamReader(stream);
json = reader.ReadToEnd();
}
// load...
JsonData input = new JsonData(json);
JsonData output = new JsonData();
try
{
DoRequest(input, output);
// did we get output?
if (!(output.ContainsKey("isOk")))
output["isOk"] = true;
}
catch(Exception ex)
{
output["isOk"] = false;
output["error"] = "General failure.";
output["generalFailure"] = ex.ToString();
}
// jqm access control bits...
context.Response.AddHeader("Access-Control-Allow-Origin", "*");
context.Response.AddHeader("Access-Control-Allow-Methods", "POST, GET");
// send...
context.Response.ContentType = "text/json";
context.Response.Write(output.ToString());
}
示例5: DataToMap
public Map DataToMap(JsonData Data)
{
mapname = Data ["Name"].ToString ();
PerfectMove = int.Parse (Data ["Step"].ToString ());
width= int.Parse (Data ["Width"].ToString ());
height= int.Parse (Data ["Height"].ToString ());
for(int i=0;i<Data["Grid"].Count;i++) {
JsonData jd=Data["Grid"][i];
GridPos.Add (new Vector2(float.Parse (jd["x"].ToString ()),float.Parse (jd["y"].ToString ())));
GridData d=new GridData(int.Parse(jd["data"][0].ToString ()),int.Parse(jd["data"][1].ToString ()),int.Parse(jd["data"][2].ToString ()));
GData.Add (d);
}
for(int i=0;i<Data["Block"].Count;i++)
{
JsonData jd=Data["Block"][i];
if(jd==null)
break;
AllBlock.Add (new Vector2(float.Parse (jd["x"].ToString ()),float.Parse (jd["y"].ToString ())));
}
GPD = new Dictionary<Vector2, GridData> ();
for (int i=0; i<GridPos.Count; i++) {
GPD.Add (GridPos[i],GData[i]);
}
return this;
}
示例6: ParseParameters
protected override void ParseParameters(JsonData parameters)
{
base.ParseParameters(parameters);
MobId = JsonUtilities.ParseInt(parameters, "mob_id");
KillerCharacterId = JsonUtilities.ParseInt(parameters, "killer_character_id");
}
示例7: CheckUser
public ActionResult CheckUser(ClientUserLoginModel model)
{
var re = new JsonData<int>();
try
{
var user = _accountService.GetAllAccounts().FirstOrDefault(u => u.AccountName == model.LoginName);
if (user != null)
{
var encryptionPassword = _encryption.GetBase64Hash(System.Text.Encoding.UTF8.GetBytes(model.Password.ToCharArray()));
if (string.Compare(encryptionPassword, user.Password, false, System.Globalization.CultureInfo.InvariantCulture) == 0)
{
re.d=user.Id;
}
else
re.m="密码错误!";
}
else
{
re.m = "登录名不存在!";
}
return Json(re);
}
catch (Exception ex)
{
Response.StatusCode = 500;
return Json(ex.Message);
}
}
示例8: Start
void Start()
{
#if UNITY_IPHONE
//ReportPolicy
//REALTIME = 0, //send log when log created
//BATCH = 1, //send log when app launch
//SENDDAILY = 4, //send log every day's first launch
//SENDWIFIONLY = 5 //send log when wifi connected
MobclickAgent.StartWithAppKeyAndReportPolicyAndChannelId("4f3122f152701529bb000042",0,"Develop");
MobclickAgent.SetAppVersion("1.2.1");
MobclickAgent.SetLogSendInterval(20);
JsonData eventAttributes = new JsonData();
eventAttributes["username"] = "Aladdin";
eventAttributes["company"] = "Umeng Inc.";
MobclickAgent.EventWithAttributes("GameState",JsonMapper.ToJson(eventAttributes));
MobclickAgent.SetLogEnabled(true);
MobclickAgent.SetCrashReportEnabled(true);
MobclickAgent.CheckUpdate();
MobclickAgent.UpdateOnlineConfig();
MobclickAgent.Event("GameState");
MobclickAgent.BeginEventWithLabel("New-GameState","identifierID");
MobclickAgent.EndEventWithLabel("New-GameState","identifierID");
#elif UNITY_ANDROID
MobclickAgent.setLogEnabled(true);
MobclickAgent.onResume();
// Android: can't call onEvent just before onResume is called, 'can't call onEvent before session is initialized' will be print in eclipse logcat
// Android: call MobclickAgent.onPause(); when Application exit.
#endif
}
示例9: LevelData
LevelData(JsonData _item)
{
try
{
JsonData item = _item;
foreach (string key in item.Keys)
{
switch (key)
{
case "Level":
Level = int.Parse(item[key].ToString());
break;
case "NeedExp":
NeedExp = int.Parse(item[key].ToString());
break;
case "Point":
Point = int.Parse(item[key].ToString());
break;
default:
Debug.LogWarning(string.Format("Level表有不明屬性:{0}", key));
break;
}
}
}
catch (Exception ex)
{
Debug.LogException(ex);
}
}
示例10: TestGetReportsByUser
public void TestGetReportsByUser()
{
ResetReports();
// create some reports..
User user = this.Creator.CreateUser();
Report report1 = this.Creator.CreateReport(user);
Report report2 = this.Creator.CreateReport(user);
Report report3 = this.Creator.CreateReport(user);
Report report4 = this.Creator.CreateReport(user);
Report report5 = this.Creator.CreateReport(user);
// get...
HandleGetReportsByUser handler = new HandleGetReportsByUser();
JsonData output = new JsonData();
handler.DoRequest(this.CreateJsonData(user), output);
// check...
string asString = output.GetValueSafe<string>("reports");
IList reports = (IList)new JavaScriptSerializer().DeserializeObject(asString);
Assert.AreEqual(5, reports.Count);
// check...
Assert.AreEqual(this.ApiKey, ((IDictionary)reports[0])["apiKey"]);
Assert.AreEqual(user.IdAsString, ((IDictionary)reports[0])["ownerUserId"]);
Assert.AreEqual(this.ApiKey, ((IDictionary)reports[1])["apiKey"]);
Assert.AreEqual(user.IdAsString, ((IDictionary)reports[1])["ownerUserId"]);
Assert.AreEqual(this.ApiKey, ((IDictionary)reports[2])["apiKey"]);
Assert.AreEqual(user.IdAsString, ((IDictionary)reports[2])["ownerUserId"]);
Assert.AreEqual(this.ApiKey, ((IDictionary)reports[3])["apiKey"]);
Assert.AreEqual(user.IdAsString, ((IDictionary)reports[3])["ownerUserId"]);
Assert.AreEqual(this.ApiKey, ((IDictionary)reports[4])["apiKey"]);
Assert.AreEqual(user.IdAsString, ((IDictionary)reports[4])["ownerUserId"]);
}
示例11: 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;
}
示例12: MachineInfo
public MachineInfo(JsonData data)
{
ParseSlots(data["slots"]);
ParseReels((IList)data["reels"]);
ParseLines((IList)data["lines"]);
ParsePayouts((IList)data["payouts"]);
}
示例13: CreateJoinMsgJson
public static JsonData CreateJoinMsgJson()
{
JsonData ret = new JsonData (JsonType.Object);
ret ["msg_type"] = MSG_R_ClientJoinWithConfig;
JsonData config = new JsonData (JsonType.Object);
config["environment_scene"] = "ProceduralGeneration";
config["random_seed"] = 1; // Omit and it will just choose one at random. Chosen seeds are output into the log(under warning or log level)."should_use_standardized_size": False,
config["standardized_size"] = new Vector3(1.0f, 1.0f, 1.0f).ToJson();
config["disabled_items"] = new JsonData(JsonType.Array); //["SQUIRL", "SNAIL", "STEGOSRS"], // A list of item names to not use, e.g. ["lamp", "bed"] would exclude files with the word "lamp" or "bed" in their file path
config["permitted_items"] = new JsonData(JsonType.Array); //["bed1", "sofa_blue", "lamp"],
config["complexity"] = 7500;
config["num_ceiling_lights"] = 4;
config["minimum_stacking_base_objects"] = 15;
config["minimum_objects_to_stack"] = 100;
config["room_width"] = 40.0f;
config["room_height"] = 15.0f;
config["room_length"] = 40.0f;
config["wall_width"] = 1.0f;
config["door_width"] = 1.5f;
config["door_height"] = 3.0f;
config["window_size_width"] = 5.0f;
config["window_size_height"] = 5.0f;
config["window_placement_height"] = 5.0f;
config["window_spacing"] = 10.0f; // Average spacing between windows on walls
config["wall_trim_height"] = 0.5f;
config["wall_trim_thickness"] = 0.01f;
config["min_hallway_width"] = 5.0f;
config["number_rooms"] = 1;
config["max_wall_twists"] = 3;
config["max_placement_attempts"] = 300; // Maximum number of failed placements before we consider a room fully filled.
config["grid_size"] = 0.4f; // Determines how fine tuned a grid the objects are placed on during Proc. Gen. Smaller the number, the
ret["config"] = config;
return ret;
}
示例14: UICall
public object UICall(JsonData data)
{
string name = data["name"].ToString();
string method = data["method"].ToString();
JsonData arg_data = data["args"];
object[] args = new object[arg_data.Count];
for (int i = 0; i < arg_data.Count; i++)
{
JsonData d = arg_data[i];
if (d.IsString) { args[i] = (string)d; continue; }
if (d.IsBoolean) { args[i] = (bool)d; continue; }
if (d.IsDouble) { args[i] = (double)d; continue; }
if (d.IsInt) { args[i] = (int)d; continue; }
if (d.IsLong) { args[i] = (long)d; continue; }
if (d.IsArray) { args[i] = d; continue; }
if (d.IsObject) { args[i] = d; continue; }
}
Component ui = UIManager.instance.Find(name);
if (ui == null)
{
Debug.LogError("UICall: can not find the ui:" + name);
return null;
}
try
{
object result = Type.GetType(name).InvokeMember(method, BindingFlags.InvokeMethod, null, ui, args);
if (result != null) return result;
}
catch (Exception ex)
{
Debug.LogError("UICall is error:" + method + ex.Message);
}
return null;
}
示例15: OnDownloadComplete
private void OnDownloadComplete(string worksheetName, JsonData[] data, string error)
{
if (m_WorksheetName == worksheetName)
{
if (!string.IsNullOrEmpty(error))
{
if (m_ProgressImage != null)
{
m_ProgressImage.fillAmount = 0;
}
if (m_ProgressText != null)
{
m_ProgressText.text = "ERROR";
}
Debug.Log("Download error on: " + m_WorksheetName + " - " + error);
}
else
{
if (m_ProgressImage != null)
{
m_ProgressImage.fillAmount = 1;
}
if (m_ProgressText != null)
{
m_ProgressText.text = 100.ToString("00.00");
}
Debug.Log("Download complete on: " + m_WorksheetName + " - " + JsonMapper.ToJson(data));
}
}
}