本文整理汇总了C#中JContainer.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JContainer.ToString方法的具体用法?C# JContainer.ToString怎么用?C# JContainer.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JContainer
的用法示例。
在下文中一共展示了JContainer.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromJObject
public static QueryAggregateDigestsRequest FromJObject(JContainer jObject)
{
var request = JsonConvert.DeserializeObject<QueryAggregateDigestsRequest>(jObject.ToString());
if (request.Constraints == null || request.Buckets == null)
{
throw new ArgumentNullException();
}
return request;
}
示例2: parseActions
/// <summary>
/// Parse the child Actions object that is part of the Tropo Result object.
/// </summary>
/// <param name="actions">Actions - is either an Object or an Array.</param>
/// <returns></returns>
public static JContainer parseActions(JContainer actions)
{
JTokenType type = actions.Type;
if (type == JTokenType.Array)
{
return JArray.Parse(actions.ToString());
}
else
{
return parseObject(actions);
}
}
示例3: PrintColoredJson
//http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript
public static void PrintColoredJson(JContainer json)
{
const string jsonPatterns =
@"(\s*""(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\""])*""(\s*:)?|\s*\b(true|false|null)\b|\s*-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?|\s*[\[\{\]\},]|\s*\n)";
const ConsoleColor keyColor = ConsoleColor.DarkGreen;
const ConsoleColor numbersColor = ConsoleColor.Cyan;
const ConsoleColor stringColor = ConsoleColor.DarkYellow;
const ConsoleColor booleanColor = ConsoleColor.DarkCyan;
const ConsoleColor nullColor = ConsoleColor.DarkMagenta;
var originalColor = Console.ForegroundColor;
try
{
var regex = new Regex(jsonPatterns, RegexOptions.None);
foreach (Match match in regex.Matches(json.ToString()))
{
if (match.Success)
{
var value = match.Groups[1].Value;
var currentColor = numbersColor;
if (Regex.IsMatch(value, "^\\s*\""))
{
currentColor = Regex.IsMatch(value, ":$") ? keyColor : stringColor;
}
else if (Regex.IsMatch(value, "true|false"))
{
currentColor = booleanColor;
}
else if (Regex.IsMatch(value, "null"))
{
currentColor = nullColor;
}
else if (Regex.IsMatch(value, @"[\[\{\]\},]"))
{
currentColor = originalColor;
}
Console.ForegroundColor = currentColor;
Console.Write(value);
}
}
}
finally
{
Console.ForegroundColor = originalColor;
}
}
示例4: parseObject
/// <summary>
/// Parse a child object that is part of a Tropo JSON payload.
/// </summary>
/// <param name="tropoObject"></param>
/// <returns></returns>
public static JObject parseObject(JContainer tropoObject)
{
return JObject.Parse(tropoObject.ToString());
}