本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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));
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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));
}
示例12: SpheroDeviceMessageDecoder
public SpheroDeviceMessageDecoder(string encodedMessage)
{
JsonReader jsonReader = new JsonReader(encodedMessage);
dictionaryRepresentation = jsonReader.Deserialize< Dictionary<string,object> >();
}
示例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);
}
示例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;
}
//.........这里部分代码省略.........
示例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();
}