本文整理汇总了C#中JsonObject.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.Exists方法的具体用法?C# JsonObject.Exists怎么用?C# JsonObject.Exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject.Exists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasSuccess
/// <summary>
/// check is status is equal success
/// </summary>
/// <param name="result">result of request</param>
/// <returns>True if status is equal success</returns>
private bool HasSuccess(string result)
{
JsonObject jsonObject = new JsonObject(result);
string status = null;
if (!jsonObject.Exists("status") || !jsonObject.TryGetString("status", out status))
{
return false;
}
return status == "success";
}
示例2: GenerateAGSToken
/// <summary>
/// 产生token
/// </summary>
/// <returns>返回一个toke,采用默认的过期时间令牌</returns>
private string GenerateAGSToken()
{
try
{
string urlGenerateToken = string.Format("{0}/generateToken", this.urlRestAdmin);
string credential = string.Format("username={0}&password={1}&client=requestip&expiration=&f=json", this.username, this.password);
string result = this.GetResult(urlGenerateToken, credential);
JsonObject jsonObject = new JsonObject(result);
string token = null;
if (!jsonObject.Exists("token") || !jsonObject.TryGetString("token", out token))
{
throw new Exception("Token not found!");
}
return token;
}
catch(Exception ex)
{
return string.Empty;
}
}
示例3: GetServerDirectory
/// <summary>
/// Get physical Path and virtual Path from directory ags
/// </summary>
/// <param name="directory">directory ags</param>
/// <param name="physicalPath">physical Path</param>
/// <param name="virtualPath">virtual Path</param>
/// <returns>True if successfully return path</returns>
public bool GetServerDirectory(string directory, out string physicalPath, out string virtualPath)
{
physicalPath = null;
virtualPath = null;
try
{
string token = this.GenerateAGSToken();
string directoryUrl = this.urlRestAdmin + "/system/directories/" + directory + "?f=json&token=" + token;
string result = this.GetResult(directoryUrl);
JsonObject jsonObject = new JsonObject(result);
if (!jsonObject.Exists("physicalPath") || !jsonObject.TryGetString("physicalPath", out physicalPath))
{
throw new Exception();
}
jsonObject = new JsonObject(result);
if (!jsonObject.Exists("virtualPath") || !jsonObject.TryGetString("virtualPath", out virtualPath))
{
throw new Exception();
}
return true;
}
catch
{
return false;
}
}
示例4: ListServices
/// <summary>
/// list of services in folder
/// </summary>
/// <param name="folder">name of folder</param>
public void ListServices(string folder)
{
try
{
string token = this.GenerateAGSToken();
string serviceUrl = this.urlRestAdmin + "/services/" + folder;
string postcontent = "f=json&token=" + token;
string result = this.GetResult(serviceUrl, postcontent);
JsonObject jsonObject = new JsonObject(result);
object[] folders = null;
if (jsonObject.Exists("folders") && jsonObject.TryGetArray("folders", out folders))
{
foreach (string subfolder in folders)
{
this.ListServices(subfolder);
}
}
object[] services = null;
if (jsonObject.Exists("services") && jsonObject.TryGetArray("services", out services))
{
IEnumerable<JsonObject> jsonObjectService = services.Cast<JsonObject>();
jsonObjectService.ToList().ForEach(jo =>
{
string serviceName;
jo.TryGetString("serviceName", out serviceName);
string folderName;
jo.TryGetString("folderName", out folderName);
Console.WriteLine(folderName + "/" + serviceName);
});
}
}
catch
{
throw;
}
}
示例5: HasError
/// <summary>
/// check is status is equal error
/// </summary>
/// <param name="result">result of request</param>
/// <returns>True if status is equal error</returns>
private bool HasError(string result)
{
JsonObject jsonObject = new JsonObject (result);
String status = null ,
if (! jsonObject.Exists ( "status" ) | |! jsonObject.TryGetString ( "status" , out status))
{
return false;
}
return status == "error";
}