当前位置: 首页>>代码示例>>C#>>正文


C# JsonValue.ToString方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:28,代码来源:JsonValueComparer.cs

示例2: Deserialize

		public object Deserialize(JsonValue value, JsonMapper mapper)
		{
			var deserializedObject = JsonConvert.DeserializeObject<CardsResponse>(value.ToString());
			deserializedObject.RawJson = value.ToString();
			return deserializedObject;
		}
开发者ID:scottksmith95,项目名称:CSharp.Geeklist,代码行数:6,代码来源:CardDeserializers.cs

示例3: Deserialize

		public object Deserialize(JsonValue value, JsonMapper mapper)
		{
			return JsonConvert.DeserializeObject<ContributionCollection>(value.ToString());
		}
开发者ID:pirimoglu,项目名称:CSharp.Readability,代码行数:4,代码来源:ContributionDeserializers.cs

示例4: Deserialize

		public object Deserialize(JsonValue value, JsonMapper mapper)
		{
			return JsonConvert.DeserializeObject<Article>(value.ToString());
		}
开发者ID:pirimoglu,项目名称:CSharp.Readability,代码行数:4,代码来源:ArticleDeserializers.cs

示例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));
            }
        }
开发者ID:karno,项目名称:Cadena,代码行数:75,代码来源:UserStreamParser.cs

示例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));
     }
 }
开发者ID:karno,项目名称:Cadena,代码行数:58,代码来源:UserStreamParser.cs

示例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));
            }
        }
开发者ID:karno,项目名称:Cadena,代码行数:101,代码来源:TwitterStreamParser.cs

示例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();
 }
开发者ID:RT-Projects,项目名称:RT.Util,代码行数:13,代码来源:HClient.cs

示例9: NewMessage

 public void NewMessage(JsonValue aMessage)
 {
     Console.WriteLine("Send {0}", aMessage.ToString());
     iBrowserTabProxy.Send(aMessage);
 }
开发者ID:weeble,项目名称:ohos,代码行数:5,代码来源:TestApp.cs

示例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;
     }
 }
开发者ID:GNOME,项目名称:chronojump,代码行数:11,代码来源:json.cs


注:本文中的JsonValue.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。