当前位置: 首页>>代码示例>>C#>>正文


C# JsonReader.Deserialize方法代码示例

本文整理汇总了C#中JsonFx.Json.JsonReader.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.Deserialize方法的具体用法?C# JsonReader.Deserialize怎么用?C# JsonReader.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonFx.Json.JsonReader的用法示例。


在下文中一共展示了JsonReader.Deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Convert

        public object Convert(int operation, string packet)
        {
            object _packet = null;
            UserOperation userOperation = (UserOperation)operation;

            JsonReader jsonReader = new JsonReader(packet);

            switch(userOperation)
            {
                case UserOperation.LOGIN:
                    _packet = jsonReader.Deserialize<LoginReply>();
                    break;
                case UserOperation.REGISTER:
                    _packet = jsonReader.Deserialize<RegisterReply>();
                    break;
                case UserOperation.CHARSELECT:
                case UserOperation.CREATECHAR:
                case UserOperation.DELETECHAR:
                case UserOperation.SELECTCHAR:
                    _packet = jsonReader.Deserialize<CharSelectPacket>();
                    break;
                default:
                    break;
            }

            return _packet;
        }
开发者ID:osROSE,项目名称:UnityRose,代码行数:27,代码来源:UserManager.cs

示例2: Convert

        public object Convert(int operation, string packet)
        {
            object _packet = null;

            CharacterOperation key = (CharacterOperation)operation;

            JsonReaderSettings settings = new JsonReaderSettings();
            settings.AddTypeConverter (new VectorConverter());
            settings.AddTypeConverter (new QuaternionConverter());

            JsonReader jsonReader = new JsonReader(packet, settings);

            switch(key)
            {
                case CharacterOperation.GROUNDCLICK:
                    _packet = jsonReader.Deserialize<GroundClick>();
                    break;
                case CharacterOperation.INSTANTIATE:
                    _packet = jsonReader.Deserialize<InstantiateChar>();
                    break;
                case CharacterOperation.DESTROY:
                    _packet = jsonReader.Deserialize<DestroyChar>();
                    break;
                default:
                    break;
            }

            return _packet;
        }
开发者ID:osROSE,项目名称:UnityRose,代码行数:29,代码来源:CharacterManager.cs

示例3: CreateJob

        public string CreateJob(string jsondata)
        {
            var newjob = new WorkerJob();

            newjob.ID = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10);

            var jr = new JsonReader(jsondata);
            var jo = jr.Deserialize() as Dictionary<string, object>;

            if (jo.ContainsKey("callback"))
                newjob.CallbackUrl = jo["callback"].ToString();

            if (jo.ContainsKey("jobtype"))
                newjob.JobType = jo["jobtype"].ToString();

            // parse args...
            if (jo.ContainsKey("jobargs"))
                Utilities.FillArgsFromJson(newjob.JobArgs, jo["jobargs"]);

            newjob.MyUrl = "http://" + _worker.Config.Hostname + ":" + _worker.Config.Port;

            Console.WriteLine("WorkerJobController: Created job #" + newjob.ID + " with callback url " + newjob.CallbackUrl);

            m_jobs.Add(newjob);
            return newjob.ID;
        }
开发者ID:possan,项目名称:mapreduce,代码行数:26,代码来源:WorkerJobController.cs

示例4: Load

 public PresetData Load(string fileName) {
     // ファイル読み込み
     try {
         using (FileStream fs = File.OpenRead(fileName))  {
             var reader = new JsonFx.Json.JsonReader(fs);
             return (PresetData)reader.Deserialize(typeof(PresetData));
         }
     } catch(Exception e) {
         LogUtil.Log("ACCプリセットの読み込みに失敗しました", e);
         return null;
     }
 }
开发者ID:trzr,项目名称:CM3D2.AlwaysColorChangeEx.Plugin,代码行数:12,代码来源:PresetManager.cs

示例5: Strings

    Strings()
    {
        var filepath = "Global";
        var text = Resources.Load(filepath) as TextAsset;

        var reader = new JsonReader(text.ToString());
        var words = reader.Deserialize() as IEnumerable;

        dict = new Dictionary<string, string> ();
        var lKey = language == SystemLanguage.Russian ? "ru" : "en";
        foreach (Dictionary<string, object> word in words)
        {
            dict[(word["key"] as string).ToLower()] = word[lKey] as string;
        }
    }
开发者ID:edspawn,项目名称:vschool,代码行数:15,代码来源:Strings.cs

示例6: GetLatestReleasedVersion

 public static Dictionary<string, object> GetLatestReleasedVersion()
 {
     Dictionary<string, object> result;
     Debugger.WriteLine(
     LogLevel.Info,
     $"Getting info about the latest version from {MaidFiddler.RELEASES_LATEST_REQUEST_URL}");
     HttpWebRequest releasesRequest = (HttpWebRequest) WebRequest.Create(MaidFiddler.RELEASES_LATEST_REQUEST_URL);
     releasesRequest.UserAgent = "Maid Fiddler Update Checker";
     releasesRequest.Accept = "application/json";
     HttpWebResponse wr = (HttpWebResponse) releasesRequest.GetResponse();
     Debugger.WriteLine(LogLevel.Info, "Got a response!");
     Debugger.WriteLine(LogLevel.Info, $"Response code: {wr.StatusCode}");
     if (!wr.ContentType.StartsWith("application/json"))
     {
         Debugger.WriteLine(
         LogLevel.Error,
         $"Could not load version data! Content gotten: {wr.ContentType} Skipping version checking...");
         return null;
     }
     JsonReader jr = new JsonReader(wr.GetResponseStream());
     result = jr.Deserialize<Dictionary<string, object>>();
     wr.Close();
     return result;
 }
开发者ID:denikson,项目名称:CM3D2.MaidFiddler,代码行数:24,代码来源:FiddlerUtils.cs

示例7: InsertFolder

	/// <summary>
	/// Insert a folder to otehr folder.
	/// </summary>
	/// <param name="parentFolder">Parent folder.</param>
	/// <returns>AsyncSuccess with File or Exception for error.</returns>
	/// <example>
	/// <code>
	/// var insert = drive.InsertFolder("new_folder_in_appdata", drive.AppData);
	/// yield return StartCoroutine(insert);
	/// </code>
	/// </example>
	public IEnumerator InsertFolder(string title, File parentFolder)
	{
		#region Check the access token is expired
		var check = CheckExpiration();
		while (check.MoveNext())
			yield return null;

		if (check.Current is Exception)
		{
			yield return check.Current;
			yield break;
		}
		#endregion

		var request = new UnityWebRequest("https://www.googleapis.com/drive/v2/files");
		request.method = "POST";
		request.headers["Authorization"] = "Bearer " + AccessToken;
		request.headers["Content-Type"] = "application/json";
		
		Dictionary<string, object> data = new Dictionary<string, object>();
		data["title"] = title;
		data["mimeType"] = "application/vnd.google-apps.folder";
		if (parentFolder != null)
		{
			data["parents"] = new List<Dictionary<string, string>>
			{
				new Dictionary<string, string> 
				{
					{ "id", parentFolder.ID }
				},
			};
		}
		request.body = Encoding.UTF8.GetBytes(JsonWriter.Serialize(data));

		var response = new UnityWebResponse(request);
		while (!response.isDone)
			yield return null;

		JsonReader reader = new JsonReader(response.text);
		var json = reader.Deserialize<Dictionary<string, object>>();

		if (json == null)
		{
			yield return new Exception(-1, "InsertFolder response parsing failed.");
			yield break;
		}
		else if (json.ContainsKey("error"))
		{
			yield return GetError(json);
			yield break;
		}

		yield return new AsyncSuccess(new File(json));
	}
开发者ID:MangoSister,项目名称:VR_Rehearsal,代码行数:65,代码来源:GoogleDriveFile.cs

示例8: Load

        /// <summary>
        /// Loads the settings from the specified settings path.
        /// </summary>
        /// <param name="settingsPath">The settings path.</param>
        public void Load(string settingsPath)
        {
            this.allSettings.Clear();

            using (StreamReader settingsReader = File.OpenText(settingsPath))
            {
                string rawSettings = settingsReader.ReadToEnd();
                JsonReader settingsJson = new JsonReader(rawSettings);
                Dictionary<string, object> settings = settingsJson.Deserialize() as Dictionary<string, object>;

                foreach (KeyValuePair<string, object> setting in settings)
                {
                    this.AddSetting(setting.Key, (string)setting.Value);
                }
            }
        }
开发者ID:indexzero,项目名称:ux-logging-toolkit,代码行数:20,代码来源:JsonApplicationSettingsService.cs

示例9: ValidateToken

	/// <summary>
	/// Validate the token and get informations.
	/// </summary>
	/// <param name="accessToken">Access token.</param>
	/// <returns>TokenInfoResponse or Exception for error</returns>
	static IEnumerator ValidateToken(string accessToken)
	{
		var request = new UnityWebRequest(
			"https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + accessToken);

		var response = request.GetResponse();
		while (!response.isDone)
			yield return null;

		if (response.error != null)
		{
			yield return response.error;
			yield break;
		}

		JsonReader reader = new JsonReader(response.text);
		var json = reader.Deserialize<Dictionary<string, object>>();

		if (json == null)
		{
			yield return new Exception(-1, "TokenInfo response parsing failed.");
			yield break;
		}

		yield return new TokenInfoResponse(json);
	}
开发者ID:MangoSister,项目名称:VR_Rehearsal,代码行数:31,代码来源:GoogleDriveAuthorization.cs

示例10: UploadText

	/// <summary>
	/// <para>Update 'my_text.txt' in the root folder.</para>
	/// <para>The file has json data.</para>
	/// </summary>
	IEnumerator UploadText()
	{
		if (drive == null || !drive.IsAuthorized || uploadTextInProgress)
			yield break;

		uploadTextInProgress = true;

		// Get 'my_text.txt'.
		var list = drive.ListFilesByQueary("title = 'my_text.txt'");
		yield return StartCoroutine(list);

		GoogleDrive.File file;
		Dictionary<string, object> data;

		var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(list);

		if (files == null || files.Count > 0)
		{
			// Found!
			file = files[0];

			// Download file data.
			var download = drive.DownloadFile(file);
			yield return StartCoroutine(download);

			var bytes = GoogleDrive.GetResult<byte[]>(download);
			try
			{
				// Data is json format.
				var reader = new JsonFx.Json.JsonReader(Encoding.UTF8.GetString(bytes));
				data = reader.Deserialize<Dictionary<string, object>>();
			}
			catch (Exception e)
			{
				Debug.LogWarning(e);

				data = new Dictionary<string, object>();
			}
		}
		else
		{
			// Make a new file.
			file = new GoogleDrive.File(new Dictionary<string, object>
			{
				{ "title", "my_text.txt" },
				{ "mimeType", "text/plain" },
				{ "description", "test" }
			});
			data = new Dictionary<string, object>();
		}

		// Update file data.
		data["date"] = DateTime.Now.ToString();
		if (data.ContainsKey("count"))
			data["count"] = (int)data["count"] + 1;
		else
			data["count"] = 0;

		// And uploading...
		{
			var bytes = Encoding.UTF8.GetBytes(JsonFx.Json.JsonWriter.Serialize(data));

			var upload = drive.UploadFile(file, bytes);
			yield return StartCoroutine(upload);

			if (!(upload.Current is Exception))
			{
				Debug.Log("Upload complete!");
			}
		}

		uploadTextInProgress = false;
	}
开发者ID:MangoSister,项目名称:VR_Rehearsal,代码行数:77,代码来源:DriveTest.cs

示例11: DuplicateFile

	/// <summary>
	/// Duplicate a file.
	/// </summary>
	/// <param name="file">File to duplicate.</param>
	/// <param name="newFile">New file data.</param>
	/// <returns>AsyncSuccess with File or Exception for error.</returns>
	/// <example>
	/// Copy 'someFile' to 'newFile'.
	/// <code>
	/// var newFile = new GoogleDrive.File(new Dictionary<string, object>
	///	{
	///		{ "title", someFile.Title + "(2)" },
	///		{ "mimeType", someFile.MimeType },
	///	});
	///	newFile.Parents = new List<string> { newParentFolder.ID };
	///	
	/// StartCoroutine(drive.DuplicateFile(someFile, newFile));
	/// </code>
	/// </example>
	IEnumerator DuplicateFile(File file, File newFile)
	{
		#region Check the access token is expired
		var check = CheckExpiration();
		while (check.MoveNext())
			yield return null;

		if (check.Current is Exception)
		{
			yield return check.Current;
			yield break;
		}
		#endregion

		var request = new UnityWebRequest("https://www.googleapis.com/drive/v2/files/" + 
			file.ID + "/copy");
		request.method = "POST";
		request.headers["Authorization"] = "Bearer " + AccessToken;
		request.headers["Content-Type"] = "application/json";

		string metadata = JsonWriter.Serialize(newFile.ToJSON());
		request.body = Encoding.UTF8.GetBytes(metadata);

		var response = new UnityWebResponse(request);
		while (!response.isDone)
			yield return null;

		JsonReader reader = new JsonReader(response.text);
		var json = reader.Deserialize<Dictionary<string, object>>();

		if (json == null)
		{
			yield return new Exception(-1, "DuplicateFile response parsing failed.");
			yield break;
		}
		else if (json.ContainsKey("error"))
		{
			yield return GetError(json);
			yield break;
		}

		yield return new AsyncSuccess(new File(json));
	}
开发者ID:MangoSister,项目名称:VR_Rehearsal,代码行数:62,代码来源:GoogleDriveFile.cs

示例12: SpheroDeviceMessageDecoder

	public SpheroDeviceMessageDecoder(string encodedMessage) 
	{
		JsonReader jsonReader = new JsonReader(encodedMessage);
		dictionaryRepresentation = jsonReader.Deserialize< Dictionary<string,object> >();
	}	
开发者ID:gustuvhx94,项目名称:UNITY-PLUGIN,代码行数:5,代码来源:SpheroDeviceMessageDecoder.cs

示例13: loadcb

		private void loadcb (string datatxt)
		{
				JsonReaderSettings setting = new JsonReaderSettings ();
				setting.AddTypeConverter (new ColorConv ());
				JsonReader reader = new JsonReader (datatxt, setting);
				Debug.Log ("+++ Deserializing +++");
				listD = reader.Deserialize<gameLevelD> ();
				Debug.Log (datatxt);
		}
开发者ID:jjhesk,项目名称:unity-interview,代码行数:9,代码来源:LoadGameData.cs

示例14: CallMethod

        protected IWebResults CallMethod(IWebConnection webConnection, IWebHandlerPlugin webHandlerPlugin, IDictionary<string, string> parameters)
        {
            object[] arguments = new object[NumParameters];

            // Decode the arguments
            foreach (KeyValuePair<string, string> parameter in parameters)
                if (ParameterIndexes.ContainsKey(parameter.Key))
                    try
                    {
                        string value = parameter.Value;
                        uint parameterIndex = ParameterIndexes[parameter.Key];

                        if (null != value)
                        {
                            ParameterInfo parameterInfo = Parameters[parameterIndex];
                            Type parameterType = parameterInfo.ParameterType;

                            // Attempt to convert the value to the requested parameter type

                            // JSON types
                            if ((typeof(Dictionary<string, string>) == parameterType)
                                || (typeof(Dictionary<string, object>) == parameterType)
                                || (parameterType.IsGenericType && typeof(Dictionary<,>) == parameterType.GetGenericTypeDefinition()))
                            {
                                JsonReader jsonReader = new JsonReader(value);
                                arguments[parameterIndex] = jsonReader.Deserialize(parameterType);
                            }
                            else if (typeof(JsonReader) == parameterType)
                                arguments[parameterIndex] = new JsonReader(value);

                            else if (typeof(bool) == parameterType || typeof(bool?) == parameterType)
                            {
                                if ("on".Equals(value.ToLower()))
                                    arguments[parameterIndex] = true;
                                else
                                    arguments[parameterIndex] = Convert.ToBoolean(value);
                            }

                            else if ((typeof(DateTime) == parameterType) || (typeof(DateTime?) == parameterType))
                            {
                                if (null != value)
                                    if (value.Length > 0)
                                    {
                                        JsonReader jsonReader = new JsonReader(value);
                                        arguments[parameterIndex] = jsonReader.Deserialize<DateTime>();
                                    }
                            }

                            else if (typeof(Guid) == parameterType || typeof(Guid?) == parameterType)
                                arguments[parameterIndex] = new Guid(value.ToString());

                            // Nullable
                            else if (parameterType.IsGenericType && typeof(Nullable<>) == parameterType.GetGenericTypeDefinition())
                            {
                                if (value.Length > 0)
                                    arguments[parameterIndex] = Convert.ChangeType(value, parameterType.GetGenericArguments()[0]);
                            }

                            // Arrays
                            else if (parameterType.IsArray)
                            {
                                JsonReader jsonReader = new JsonReader(value);
                                arguments[parameterIndex] = jsonReader.Deserialize(parameterType);
                            }

                            // Everything else
                            else
                                arguments[parameterIndex] = Convert.ChangeType(value, parameterType);
                        }
                        else
                            arguments[parameterIndex] = null;
                    }
                    catch (JsonDeserializationException jde)
                    {
                        throw new WebResultsOverrideException(WebResults.From(
                            Status._400_Bad_Request,
                            "Error parsing " + parameter.Key + ", Bad JSON: " + jde.Message));
                    }
                    catch
                    {
                        throw new WebResultsOverrideException(WebResults.From(
                            Status._400_Bad_Request,
                            "Error parsing " + parameter.Key));
                    }

            // The first argument is always the web connection
            arguments[0] = webConnection;

            object toReturn;

            try
            {
                toReturn = MethodInfo.Invoke(webHandlerPlugin, arguments);
            }
            catch (TargetInvocationException e)
            {
                // Invoke wraps exceptions
                throw e.InnerException;
            }

//.........这里部分代码省略.........
开发者ID:GWBasic,项目名称:ObjectCloud,代码行数:101,代码来源:UrlEncoded.cs

示例15: DeleteFile

	/// <summary>
	/// Delete a file(or folder).
	/// </summary>
	/// <param name="file">File.</param>
	/// <returns>AsyncSuccess or Exception for error.</returns>
	/// <example>
	/// Delete all files.
	/// <code>
	/// var listFiles = drive.ListAllFiles();
	/// yield return StartCoroutine(listFiles);
	/// var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);
	/// 
	/// if (files != null)
	/// {
	///		for (int i = 0; i < files.Count; i++)
	///			yield return StartCoroutine(drive.DeleteFile(files[i]));
	/// }
	/// </code>
	/// </example>
	public IEnumerator DeleteFile(File file)
	{
		#region Check the access token is expired
		var check = CheckExpiration();
		while (check.MoveNext())
			yield return null;

		if (check.Current is Exception)
		{
			yield return check.Current;
			yield break;
		}
		#endregion

		var request = new UnityWebRequest("https://www.googleapis.com/drive/v2/files/" + file.ID);
		request.method = "DELETE";
		request.headers["Authorization"] = "Bearer " + AccessToken;

		var response = new UnityWebResponse(request);
		while (!response.isDone)
			yield return null;

		// If successful, empty response.
		JsonReader reader = new JsonReader(response.text);
		var json = reader.Deserialize<Dictionary<string, object>>();
		
		if (json != null && json.ContainsKey("error"))
		{
			yield return GetError(json);
			yield break;
		}

		yield return new AsyncSuccess();
	}
开发者ID:MangoSister,项目名称:VR_Rehearsal,代码行数:53,代码来源:GoogleDriveFile.cs


注:本文中的JsonFx.Json.JsonReader.Deserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。