本文整理汇总了C#中WPCordovaClassLib.Cordova.PluginResult.ToJSONString方法的典型用法代码示例。如果您正苦于以下问题:C# PluginResult.ToJSONString方法的具体用法?C# PluginResult.ToJSONString怎么用?C# PluginResult.ToJSONString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WPCordovaClassLib.Cordova.PluginResult
的用法示例。
在下文中一共展示了PluginResult.ToJSONString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCommandResult
/// <summary>
/// Handles command execution result.
/// </summary>
/// <param name="callbackId">Command callback identifier on client side</param>
/// <param name="result">Execution result</param>
private void OnCommandResult(string callbackId, PluginResult result)
{
#region args checking
if (result == null)
{
Debug.WriteLine("ERROR: OnCommandResult missing result argument");
return;
}
if (String.IsNullOrEmpty(callbackId))
{
Debug.WriteLine("ERROR: OnCommandResult missing callbackId argument");
return;
}
#endregion
string status = ((int)result.Result).ToString();
string jsonResult = result.ToJSONString();
ScriptCallback scriptCallback = null;
if (String.IsNullOrEmpty(result.Cast))
{
scriptCallback = new ScriptCallback("CordovaCommandResult", new string[] { status, callbackId, jsonResult });
}
else
{
scriptCallback = new ScriptCallback("CordovaCommandResult", new string[] { status, callbackId, jsonResult, result.Cast });
}
this.InvokeScriptCallback(scriptCallback);
}
示例2: OnCommandResult
/// <summary>
/// Handles command execution result.
/// </summary>
/// <param name="callbackId">Command callback identifier on client side</param>
/// <param name="result">Execution result</param>
private void OnCommandResult(string callbackId, PluginResult result)
{
#region args checking
if (result == null)
{
Debug.WriteLine("ERROR: OnCommandResult missing result argument");
return;
}
if (String.IsNullOrEmpty(callbackId))
{
Debug.WriteLine("ERROR: OnCommandResult missing callbackId argument");
return;
}
if (!String.IsNullOrEmpty(result.CallbackId) && callbackId != result.CallbackId)
{
Debug.WriteLine("Multiple Overlapping Results :: " + result.CallbackId + " :: " + callbackId);
return;
}
#endregion
string jsonResult = result.ToJSONString();
string callback;
string args = string.Format("('{0}',{1});", callbackId, jsonResult);
if (result.Result == PluginResult.Status.NO_RESULT ||
result.Result == PluginResult.Status.OK)
{
callback = @"(function(callbackId,args) {
try { args.message = JSON.parse(args.message); } catch (ex) { }
cordova.callbackSuccess(callbackId,args);
})" + args;
}
else
{
callback = @"(function(callbackId,args) {
try { args.message = JSON.parse(args.message); } catch (ex) { }
cordova.callbackError(callbackId,args);
})" + args;
}
this.InvokeScriptCallback(new ScriptCallback("eval", new string[] { callback }));
}