本文整理汇总了C#中JContainer类的典型用法代码示例。如果您正苦于以下问题:C# JContainer类的具体用法?C# JContainer怎么用?C# JContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JContainer类属于命名空间,在下文中一共展示了JContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public static byte[] Serialize(JContainer item)
{
var stringWriter = new StringWriter();
var writer = new JsonTextWriter(stringWriter);
item.WriteTo(writer);
return Encoding.UTF8.GetBytes(stringWriter.ToString());
}
示例2: FillWithJsonObject
public void FillWithJsonObject(JContainer dict, Scheme scheme)
{
Title = (string)dict["title"];
Id = (string)dict["id"];
Color = (Color)ColorConverter.ConvertFromString((string)dict["color"]);
Points = (dict["points"]).Select(p => new Point((double)p[0], (double)p[1])).ToArray();
}
示例3: JTokenWriter
/// <summary>
/// Initializes a new instance of the <see cref="JTokenWriter"/> class writing to the given <see cref="JContainer"/>.
/// </summary>
/// <param name="container">The container being written to.</param>
public JTokenWriter(JContainer container)
{
ValidationUtils.ArgumentNotNull(container, "container");
_token = container;
_parent = container;
}
示例4: AddParent
private void AddParent(JContainer container)
{
if (this._parent == null)
this._token = container;
else
this._parent.AddAndSkipParentCheck((JToken) container);
this._parent = container;
}
示例5: FillWithJsonObject
public virtual void FillWithJsonObject(JContainer dict, Scheme scheme)
{
Title = (string)dict["title"];
Room = scheme.Rooms.Single(r => r.Id.Equals(dict["room"]));
QRCode = (string)dict[@"qr_code"];
Image = (string)dict["image"];
Visible = (bool)dict[@"visible"];
}
示例6: _SendHttpRequest
/**
* @param uri
* @param method Case-insensitive
* @param bodyObject
* @param responseObject output, the value would be JObject or JArray
*/
private bool _SendHttpRequest(string uri, string method, JObject bodyObject, out JContainer responseObject)
{
responseObject = null;
var url = APIEndPoint + BaseURL + @"/" + uri;
// Set remote url and http method.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = method;
// Set the content type header and http body.
if(bodyObject != null){
var body = JsonConvert.SerializeObject(bodyObject);
if (body.Length != 0)
{
request.ContentType = "application/json";
using (Stream requestStream = request.GetRequestStream())
using (StreamWriter writer = new StreamWriter(requestStream))
{
writer.Write(body);
}
}
}
// Set the authorization id.
string sAuth = "auth_id=" + AuthoId;
request.Headers.Add("Authorization", sAuth);
string responseData = "";
try
{
// Send request
System.Net.WebResponse response = (HttpWebResponse)request.GetResponse();
responseData = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
catch (WebException e)
{
HttpWebResponse response = (HttpWebResponse)e.Response;
if (response != null)
{
responseData = new StreamReader(response.GetResponseStream()).ReadToEnd();
response.Close(); // Releases the resources of the response.
}
}
catch (Exception)
{
return false;
}
if (!string.IsNullOrEmpty(responseData))
{
var res = JsonConvert.DeserializeObject(responseData);
responseObject = res as JContainer;
}
return true;
}
示例7: AddParent
private void AddParent(JContainer container)
{
if (_parent == null)
_token = container;
else
_parent.Add(container);
_parent = container;
}
示例8: 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;
}
示例9: FormatLinks
public void FormatLinks(JContainer container, IEnumerable<Link> links, JsonSerializer serializer)
{
var jLinks = new JArray();
foreach (var link in links)
{
jLinks.Add(JObject.FromObject(link, serializer));
}
container[_linksPropertyName] = jLinks;
}
示例10: FormatLinks
public void FormatLinks(JContainer container, IEnumerable<Link> links, JsonSerializer serializer)
{
var jLinks = new JObject();
foreach (var link in links)
{
jLinks[link.Rel] = JValue.CreateString(link.Href);
}
container[_linksPropertyName] = jLinks;
}
示例11: AssertSchemaIsValid
public static void AssertSchemaIsValid(JSchema jSchema, JContainer jContainer)
{
IList<string> messages;
var isValid = jContainer.IsValid(jSchema, out messages);
foreach (var message in messages)
{
Console.WriteLine(message);
}
Assert.IsTrue(isValid);
}
示例12: 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);
}
}
示例13: ReadInto
private bool ReadInto(JContainer c)
{
JToken firstChild = c.First;
if (firstChild == null)
{
return SetEnd(c);
}
else
{
SetToken(firstChild);
_current = firstChild;
_parent = c;
return true;
}
}
示例14: GetEndToken
private JsonToken? GetEndToken(JContainer c)
{
switch (c.Type)
{
case JsonTokenType.Object:
return JsonToken.EndObject;
case JsonTokenType.Array:
return JsonToken.EndArray;
case JsonTokenType.Constructor:
return JsonToken.EndConstructor;
case JsonTokenType.Property:
return null;
default:
throw MiscellaneousUtils.CreateArgumentOutOfRangeException("Type", c.Type, "Unexpected JContainer type.");
}
}
示例15: GeneratePatterns
/// <summary>
/// Generates a collection of patterns for the specified <see cref="JContainer"/>.
/// </summary>
public PatternCollection GeneratePatterns(JContainer root, int desiredCount, bool skipValues = true)
{
var descendants = root.DescendantsAndSelf().ToArray();
descendants.Shuffle(random);
if (skipValues)
descendants = descendants.Where(x => x is JObject || x is JArray).ToArray();
var patterns = descendants
.Select(x => x.Path)
.Where(x => !string.IsNullOrWhiteSpace(x))
.Take(desiredCount)
.Select(x => (random.NextBool() ? "!" : "") + x)
.Select(AddWildcards)
.ToArray();
return PatternCollection.Parse(patterns);
}