本文整理汇总了C#中JsonValue.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JsonValue.ToString方法的具体用法?C# JsonValue.ToString怎么用?C# JsonValue.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonValue
的用法示例。
在下文中一共展示了JsonValue.ToString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compare
/// <summary>
/// Compares two JsonValue objects.
/// </summary>
/// <param name="expected">The expected JsonValue.</param>
/// <param name="actual">The actual JsonValue.</param>
public void Compare(JsonValue expected, JsonValue actual)
{
assert.AreEqual(expected.JsonType, actual.JsonType, "The types of nodes '{0}' and '{1}' are not equal.", expected.ToString(), actual.ToString());
switch (expected.JsonType)
{
case JsonValueType.JsonProperty:
CompareProperty((JsonProperty)expected, (JsonProperty)actual);
break;
case JsonValueType.JsonObject:
CompareObject((JsonObject)expected, (JsonObject)actual);
break;
case JsonValueType.JsonArray:
CompareArray((JsonArray)expected, (JsonArray)actual);
break;
case JsonValueType.JsonPrimitiveValue:
ComparePrimitiveValue((JsonPrimitiveValue)expected, (JsonPrimitiveValue)actual);
break;
default:
assert.Fail("Unexpected JsonType value '{0}'.", expected.JsonType);
break;
}
}
示例2: Deserialize
public object Deserialize(JsonValue value, JsonMapper mapper)
{
var deserializedObject = JsonConvert.DeserializeObject<CardsResponse>(value.ToString());
deserializedObject.RawJson = value.ToString();
return deserializedObject;
}
示例3: Deserialize
public object Deserialize(JsonValue value, JsonMapper mapper)
{
return JsonConvert.DeserializeObject<ContributionCollection>(value.ToString());
}
示例4: Deserialize
public object Deserialize(JsonValue value, JsonMapper mapper)
{
return JsonConvert.DeserializeObject<Article>(value.ToString());
}
示例5: ParseStreamLine
/// <summary>
/// Parse streamed JSON line
/// </summary>
/// <param name="graph">JSON object graph</param>
/// <param name="handler">result handler</param>
public static void ParseStreamLine(JsonValue graph, IStreamHandler handler)
{
try
{
// element.foo() -> element.IsDefined("foo")
//
// fast path: first, identify standard status payload
////////////////////////////////////////////////////////////////////////////////////
if (TwitterStreamParser.ParseStreamLineAsStatus(graph, handler))
{
return;
}
//
// parse stream-specific elements
//
// friends lists
var friends = graph["friends"].AsArrayOrNull();
if (friends != null)
{
// friends enumeration
var friendsIds = friends.Select(v => v.AsLong()).ToArray();
handler.OnMessage(new StreamEnumeration(friendsIds));
return;
}
friends = graph["friends_str"].AsArrayOrNull();
if (friends != null)
{
// friends enumeration(stringified)
var friendsIds = friends.Select(v => v.AsString().ParseLong()).ToArray();
handler.OnMessage(new StreamEnumeration(friendsIds));
return;
}
var @event = graph["event"].AsString();
if (@event != null)
{
ParseStreamEvent(@event.ToLower(), graph, handler);
return;
}
// too many follows warning
var warning = graph["warning"].AsObjectOrNull();
if (warning != null)
{
var code = warning["code"].AsString();
if (code == "FOLLOWS_OVER_LIMIT")
{
handler.OnMessage(new StreamTooManyFollowsWarning(
code,
warning["message"].AsString(),
warning["user_id"].AsLong(),
TwitterStreamParser.GetTimestamp(warning)));
return;
}
}
// fallback to default stream handler
TwitterStreamParser.ParseNotStatusStreamLine(graph, handler);
}
catch (Exception ex)
{
handler.OnException(new StreamParseException(
"Stream graph parse failed.", graph.ToString(), ex));
}
}
示例6: ParseStreamEvent
/// <summary>
/// Parse streamed twitter event
/// </summary>
/// <param name="ev">event name</param>
/// <param name="graph">JSON object graph</param>
/// <param name="handler">result handler</param>
private static void ParseStreamEvent(string ev, JsonValue graph, IStreamHandler handler)
{
try
{
var source = new TwitterUser(graph[EventSourceKey]);
var target = new TwitterUser(graph[EventTargetKey]);
var timestamp = graph[EventCreatedAtKey].AsString().ParseTwitterDateTime();
switch (ev)
{
case "favorite":
case "unfavorite":
case "quoted_tweet":
case "favorited_retweet":
case "retweeted_retweet":
handler.OnMessage(new StreamStatusEvent(source, target,
new TwitterStatus(graph[EventTargetObjectKey]), ev, timestamp));
break;
case "block":
case "unblock":
case "follow":
case "unfollow":
case "mute":
case "unmute":
case "user_update":
case "user_delete":
case "user_suspend":
handler.OnMessage(new StreamUserEvent(source, target,
ev, timestamp));
break;
case "list_created":
case "list_destroyed":
case "list_updated":
case "list_member_added":
case "list_member_removed":
case "list_user_subscribed":
case "list_user_unsubscribed":
handler.OnMessage(new StreamListEvent(source, target,
new TwitterList(graph[EventTargetObjectKey]), ev, timestamp));
break;
case "access_revoked":
case "access_unrevoked":
handler.OnMessage(new StreamAccessInformationEvent(source, target,
new AccessInformation(graph[EventTargetObjectKey]), ev, timestamp));
break;
}
}
catch (Exception ex)
{
handler.OnException(new StreamParseException(
"Event parse failed:" + ev, graph.ToString(), ex));
}
}
示例7: ParseNotStatusStreamLine
//.........这里部分代码省略.........
// scrub_geo
JsonValue scrubGeo;
if (graph.TryGetValue("scrub_geo", out scrubGeo))
{
handler.OnMessage(new StreamScrubGeo(
Int64.Parse(scrubGeo["user_id_str"].AsString()),
Int64.Parse(scrubGeo["up_to_status_id_str"].AsString()),
GetTimestamp(scrubGeo)));
return;
}
// limit
JsonValue limit;
if (graph.TryGetValue("limit", out limit))
{
handler.OnMessage(new StreamLimit(
limit["track"].AsLong(),
GetTimestamp(limit)));
return;
}
// withheld
JsonValue statusWithheld;
if (graph.TryGetValue("status_withheld", out statusWithheld))
{
handler.OnMessage(new StreamWithheld(
statusWithheld["user_id"].AsLong(),
statusWithheld["id"].AsLong(),
((JsonArray)statusWithheld["withheld_in_countries"]).Select(s => s.AsString()).ToArray(),
GetTimestamp(statusWithheld)));
return;
}
JsonValue userWithheld;
if (graph.TryGetValue("user_withheld", out userWithheld))
{
handler.OnMessage(new StreamWithheld(
userWithheld["id"].AsLong(),
((JsonArray)statusWithheld["withheld_in_countries"]).Select(s => s.AsString()).ToArray(),
GetTimestamp(statusWithheld)));
return;
}
// disconnect
JsonValue disconnect;
if (graph.TryGetValue("disconnect", out disconnect))
{
handler.OnMessage(new StreamDisconnect(
(DisconnectCode)disconnect["code"].AsLong(),
disconnect["stream_name"].AsString(),
disconnect["reason"].AsString(),
GetTimestamp(disconnect)));
return;
}
// stall warning
JsonValue warning;
if (graph.TryGetValue("warning", out warning))
{
var timestamp = GetTimestamp(warning);
var code = warning["code"].AsString();
if (code == "FALLING_BEHIND")
{
handler.OnMessage(new StreamStallWarning(
code,
warning["message"].AsString(),
(int)warning["percent_full"].AsLong(),
timestamp));
return;
}
}
// user update
JsonValue @event;
if (graph.TryGetValue("event", out @event))
{
var ev = @event.AsString().ToLower();
if (ev == "user_update")
{
// parse user_update only in generic streams.
handler.OnMessage(new StreamUserEvent(
new TwitterUser(graph["source"]),
new TwitterUser(graph["target"]),
ev, graph["created_at"].AsString().ParseTwitterDateTime()));
return;
}
// unknown event...
handler.OnMessage(new StreamUnknownMessage("event: " + ev, graph.ToString()));
}
// unknown event-type...
handler.OnMessage(new StreamUnknownMessage(null, graph.ToString()));
}
catch (Exception ex)
{
handler.OnException(new StreamParseException(
"Stream graph parse failed.", graph.ToString(), ex));
}
}
示例8: HArg
/// <summary>
/// Constructor for a key-value argument (not a file upload).</summary>
/// <param name="name">
/// Name of the argument.</param>
/// <param name="value">
/// Value of the argument. This value is encoded as JSON syntax.</param>
/// <seealso cref="HArg(string,string)"/>
/// <seealso cref="HArg(string,string,string,byte[])"/>
public HArg(string name, JsonValue value)
{
Name = name;
Value = value.ToString();
}
示例9: NewMessage
public void NewMessage(JsonValue aMessage)
{
Console.WriteLine("Send {0}", aMessage.ToString());
iBrowserTabProxy.Send(aMessage);
}
示例10: valueOrDefault
public static JsonValue valueOrDefault(JsonValue jsonObject, string key, string defaultValue)
{
// Returns jsonObject[key] if it exists. If the key doesn't exist returns defaultValue and
// logs the anomaly into the Chronojump log.
if (jsonObject.ContainsKey (key)) {
return jsonObject [key];
} else {
LogB.Information ("JsonUtils::valueOrDefault: returning default (" + defaultValue + ") from JSON: " + jsonObject.ToString ());
return defaultValue;
}
}