本文整理汇总了C#中Newtonsoft.Json.Linq.JObject类的典型用法代码示例。如果您正苦于以下问题:C# JObject类的具体用法?C# JObject怎么用?C# JObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JObject类属于Newtonsoft.Json.Linq命名空间,在下文中一共展示了JObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BetRequest
public static int BetRequest(JObject jsonState)
{
int bet = 0;
var gameState = JsonConvert.DeserializeObject<GameState>(jsonState.ToString());
try
{
string actualDecision = "none";
Logger.LogHelper.Log("type=bet_begin action=bet_request request_id={0} game_id={1}", requestId, gameState.GameId);
foreach (IDecisionLogic decisionLogic in Decisions.DecisionFactory.GetDecisions())
{
//végigpróbáljuk a lehetőségeket
int? possibleBet = decisionLogic.MakeADecision(gameState);
if (possibleBet.HasValue)
{
bet = possibleBet.Value;
actualDecision = decisionLogic.GetName();
break;
}
}
string cards = String.Join(",", gameState.OwnCards);
Logger.LogHelper.Log("type=bet action=bet_request request_id={0} game_id={1} bet={2} cards={3} decision={4}",
requestId, gameState.GameId, bet, cards, actualDecision);
}
catch (Exception ex)
{
Logger.LogHelper.Error("type=error action=bet_request request_id={0} game_id={1} error_message={2}",requestId, gameState.GameId, ex);
}
return bet;
}
示例2: HasRed
private static bool HasRed(JObject jObject)
{
return jObject.Properties()
.Select(x => x.Value)
.OfType<JValue>()
.Any(x => x.Value<string>() == "red");
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
var obj = new JObject(new JProperty("machineName", ServerManager.MachineName), new JProperty("servers", JArray.FromObject(ServerManager.GetActiveServerList())));
Response.BinaryWrite(Encoding.UTF8.GetBytes(obj.ToString()));
Response.End();
}
示例4: ReadElement
public IEnumerable<JObject> ReadElement(IAixmConverter converter, JObject currentObject, XElement element)
{
currentObject.AddToProperties("elevation", JObject.FromObject(element));
//If not a feature return null;
return Enumerable.Empty<JObject>();
}
示例5: ItemListStatic
public ItemListStatic(JObject basicO,
JObject dataO,
JArray groupsA,
JArray treeA,
string type,
string version,
JObject originalObject)
{
data = new Dictionary<string, ItemStatic>();
groups = new List<GroupStatic>();
tree = new List<ItemTreeStatic>();
if (basicO != null)
{
basic = HelperMethods.LoadBasicDataStatic(basicO);
}
if (dataO != null)
{
LoadData(dataO.ToString());
}
if (groupsA != null)
{
LoadGroups(groupsA);
}
if (treeA != null)
{
LoadTree(treeA);
}
this.type = type;
this.version = version;
this.originalObject = originalObject;
}
示例6: ToJSON
public static JObject ToJSON(this QueryResult myQueryResult)
{
// root element...
var _Query = new JObject();
// query --------------------------------
_Query.Add(new JProperty("query", myQueryResult.Query));
// result -------------------------------
_Query.Add(new JProperty("result", myQueryResult.ResultType.ToString()));
// duration -----------------------------
_Query.Add(new JProperty("duration", new JArray(myQueryResult.Duration, "ms")));
// warnings -----------------------------
_Query.Add(new JProperty("warnings", new JArray(
from _Warning in myQueryResult.Warnings
select new JObject(
new JProperty("code", _Warning.GetType().ToString()),
new JProperty("description", _Warning.ToString())
))));
// errors -------------------------------
_Query.Add(new JProperty("errors", new JArray(
from _Error in myQueryResult.Errors
select new JObject(
new JProperty("code", _Error.GetType().ToString()),
new JProperty("description", _Error.ToString())
))));
// results ------------------------------
_Query.Add(new JProperty("results", new JArray(GetJObjectsFromResult(myQueryResult.Vertices))));
return _Query;
}
示例7: GetTypeFromJObject
private IElasticCoreType GetTypeFromJObject(JObject po, JsonSerializer serializer)
{
JToken typeToken;
serializer.TypeNameHandling = TypeNameHandling.None;
if (po.TryGetValue("type", out typeToken))
{
var type = typeToken.Value<string>().ToLowerInvariant();
switch (type)
{
case "string":
return serializer.Deserialize(po.CreateReader(), typeof(StringMapping)) as StringMapping;
case "float":
case "double":
case "byte":
case "short":
case "integer":
case "long":
return serializer.Deserialize(po.CreateReader(), typeof(NumberMapping)) as NumberMapping;
case "date":
return serializer.Deserialize(po.CreateReader(), typeof(DateMapping)) as DateMapping;
case "boolean":
return serializer.Deserialize(po.CreateReader(), typeof(BooleanMapping)) as BooleanMapping;
case "binary":
return serializer.Deserialize(po.CreateReader(), typeof(BinaryMapping)) as BinaryMapping;
}
}
return null;
}
示例8: PackInclude_is_null_when_it_is_not_set_in_the_ProjectJson
public void PackInclude_is_null_when_it_is_not_set_in_the_ProjectJson()
{
var json = new JObject();
var project = GetProject(json);
project.PackOptions.PackInclude.Should().BeNull();
}
示例9: CreateEDDNMessage
public JObject CreateEDDNMessage(JournalFSDJump journal)
{
if (!journal.HasCoordinate)
return null;
JObject msg = new JObject();
msg["header"] = Header();
msg["$schemaRef"] = "http://schemas.elite-markets.net/eddn/journal/1/test";
JObject message = new JObject();
message["StarSystem"] = journal.StarSystem;
message["Government"] = journal.Government;
message["timestamp"] = journal.EventTimeUTC.ToString("yyyy-MM-ddTHH:mm:ssZ");
message["Faction"] = journal.Faction;
message["Allegiance"] = journal.Allegiance;
message["StarPos"] = new JArray(new float[] { journal.StarPos.X, journal.StarPos.Y, journal.StarPos.Z });
message["Security"] = journal.Security;
message["event"] = journal.EventTypeStr;
message["Economy"] = journal.Economy;
msg["message"] = message;
return msg;
}
示例10: FromJson
internal static XbmcAlbum FromJson(JObject obj)
{
if (obj == null)
{
return null;
}
try
{
return new XbmcAlbum(JsonRpcClient.GetField<int>(obj, "albumid"),
JsonRpcClient.GetField<string>(obj, "thumbnail"),
JsonRpcClient.GetField<string>(obj, "fanart"),
JsonRpcClient.GetField<string>(obj, "album_title"),
JsonRpcClient.GetField<string>(obj, "album_artist"),
JsonRpcClient.GetField<int>(obj, "year"),
JsonRpcClient.GetField<int>(obj, "album_rating"),
JsonRpcClient.GetField<string>(obj, "album_genre", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_mood", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_theme", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_style", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_type", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_label", string.Empty),
JsonRpcClient.GetField<string>(obj, "album_description", string.Empty));
}
catch (Exception ex)
{
return null;
}
}
示例11: AddMasterFieldToDataset
public HttpResponseMessage AddMasterFieldToDataset(JObject jsonData)
{
var db = ServicesContext.Current;
dynamic json = jsonData;
int DatasetId = json.DatasetId.ToObject<int>();
var dataset = db.Datasets.Find(DatasetId);
int FieldId = json.FieldId.ToObject<int>();
var field = db.Fields.Find(FieldId);
DatasetField df = new DatasetField();
df.DatasetId = dataset.Id;
df.FieldId = field.Id;
df.FieldRoleId = FieldRole.DETAIL;
df.CreateDateTime = DateTime.Now;
df.Label = field.Name;
df.DbColumnName = field.DbColumnName;
df.SourceId = 1;
df.ControlType = field.ControlType;
db.DatasetFields.Add(df);
db.SaveChanges();
return new HttpResponseMessage(HttpStatusCode.OK);
}
示例12: Event
public Event(int appId, string @event, string entityId, string entityType, string targetEntityId, string targetEntityType, Dictionary<string, object> properties)
{
this[Constants.AppId] = appId;
this[Constants.Event] = @event;
this[Constants.EntityType] = entityType;
this[Constants.EntityId] = entityId;
if (!string.IsNullOrWhiteSpace(targetEntityId))
{
this[Constants.TargetEntityId] = targetEntityId;
}
if (!string.IsNullOrWhiteSpace(targetEntityType))
{
this[Constants.TargetEntityType] = targetEntityType;
}
if (properties != null)
{
var jProperties = new JObject();
foreach (var property in properties)
{
jProperties[property.Key] = JToken.FromObject(property.Value);
}
this[Constants.Properties] = jProperties;
}
this[Constants.EventTime] = new DateTimeAdapter().Serialize(DateTime.UtcNow);
}
示例13: newLegend
JObject newLegend(string[] _legend)
{
JObject legend = new JObject(
new JProperty("data", _legend)
);
return legend;
}
示例14: newCategory
JObject newCategory(string _category)
{
JObject category = new JObject(
new JProperty("name",_category)
);
return category;
}
示例15: ContentTypeDefinition
public ContentTypeDefinition(string name, string displayName)
{
Name = name;
DisplayName = displayName;
Parts = Enumerable.Empty<ContentTypePartDefinition>();
Settings = new JObject();
}