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


C# JsonValue.ContainsKey方法代码示例

本文整理汇总了C#中JsonValue.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# JsonValue.ContainsKey方法的具体用法?C# JsonValue.ContainsKey怎么用?C# JsonValue.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonValue的用法示例。


在下文中一共展示了JsonValue.ContainsKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TwitterStatus

        internal TwitterStatus(JsonValue json)
        {
            // read numeric id and timestamp
            Id = json["id_str"].AsString().ParseLong();
            CreatedAt = json["created_at"].AsString().ParseDateTime(ParsingExtension.TwitterDateTimeFormat);

            // check extended_tweet is existed
            var exjson = json.ContainsKey("extended_tweet") ? json["extended_tweet"] : json;

            // read full_text ?? text
            var text = exjson.ContainsKey("full_text") ? exjson["full_text"] : exjson["text"];
            Text = ParsingExtension.ResolveEntity(text.AsString());

            var array = exjson["display_text_range"].AsArrayOrNull()?.AsLongArray();
            if (array != null && array.Length >= 2)
            {
                DisplayTextRange = new Tuple<int, int>((int)array[0], (int)array[1]);
            }

            if (exjson.ContainsKey("extended_entities"))
            {
                // get correctly typed entities array
                var orgEntities = TwitterEntity.ParseEntities(json["entities"]).ToArray();
                var extEntities = TwitterEntity.ParseEntities(json["extended_entities"]).ToArray();

                // merge entities
                Entities = orgEntities.Where(e => !(e is MediaEntity))
                                      .Concat(extEntities) // extended entities contains media entities only.
                                      .ToArray();
            }
            else if (exjson.ContainsKey("entities"))
            {
                Entities = TwitterEntity.ParseEntities(exjson["entities"]).ToArray();
            }
            else
            {
                Entities = new TwitterEntity[0];
            }
            if (json.ContainsKey("recipient"))
            {
                // THIS IS DIRECT MESSAGE!
                StatusType = StatusType.DirectMessage;
                User = new TwitterUser(json["sender"]);
                Recipient = new TwitterUser(json["recipient"]);
            }
            else
            {
                StatusType = StatusType.Tweet;
                User = new TwitterUser(json["user"]);
                Source = json["source"].AsString();
                InReplyToStatusId = json["in_reply_to_status_id_str"].AsString().ParseNullableId();
                InReplyToUserId = json["in_reply_to_user_id_str"].AsString().ParseNullableId();
                InReplyToScreenName = json["in_reply_to_screen_name"].AsString();

                if (json.ContainsKey("retweeted_status"))
                {
                    var retweeted = new TwitterStatus(json["retweeted_status"]);
                    RetweetedStatus = retweeted;
                    RetweetedStatusId = retweeted.Id;
                    // merge text and entities
                    Text = retweeted.Text;
                    Entities = retweeted.Entities;
                }
                if (json.ContainsKey("quoted_status"))
                {
                    var quoted = new TwitterStatus(json["quoted_status"]);
                    QuotedStatus = quoted;
                    QuotedStatusId = quoted.Id;
                }
                var coordinates = json["coordinates"].AsArrayOrNull()?.AsDoubleArray();
                if (coordinates != null)
                {
                    Longitude = coordinates[0];
                    Latitude = coordinates[1];
                }
            }
        }
开发者ID:karno,项目名称:Cadena,代码行数:77,代码来源:TwitterStatus.cs

示例2: ParseStreamLineAsStatus

 /// <summary>
 /// Check parse streamed JSON line as normal (not direct-message) status
 /// </summary>
 /// <param name="graph">JSON object graph</param>
 /// <param name="handler">stream handler</param>
 /// <returns></returns>
 internal static bool ParseStreamLineAsStatus(JsonValue graph, IStreamHandler handler)
 {
     if (!graph.ContainsKey("text")) return false;
     handler.OnStatus(new TwitterStatus(graph));
     return true;
 }
开发者ID:karno,项目名称:Cadena,代码行数:12,代码来源:TwitterStreamParser.cs

示例3: GetTimestamp

 /// <summary>
 /// Get timestamp_ms field or pseudo timestamp string.
 /// </summary>
 /// <param name="graph">json object graph</param>
 /// <returns>timestamp code(millisec)</returns>
 internal static string GetTimestamp(JsonValue graph)
 {
     return graph.ContainsKey("timestamp_ms")
         ? graph["timestamp_ms"].AsString()
         : ((long)(DateTime.Now.ToUniversalTime() - StreamMessage.SerialTime)
             .TotalMilliseconds).ToString();
 }
开发者ID:karno,项目名称:Cadena,代码行数:12,代码来源:TwitterStreamParser.cs

示例4: DictionaryLiteral

    public void DictionaryLiteral()
    {
        JsonValue test = new JsonValue() {
            {"three", 3},
            {"two", 2},
            {"one", 1},
            {"blast", "off!"}
        };
        Assert.That(test.Type, Is.EqualTo(JsonType.Object));

        Assert.That(test.ContainsKey("three"), Is.True);
        Assert.That(test.ContainsKey("two"), Is.True);
        Assert.That(test.ContainsKey("one"), Is.True);
        Assert.That(test.ContainsKey("blast"), Is.True);

        Assert.That(test["three"].Type, Is.EqualTo(JsonType.Int));
        Assert.That(test["two"].Type, Is.EqualTo(JsonType.Int));
        Assert.That(test["one"].Type, Is.EqualTo(JsonType.Int));
        Assert.That(test["blast"].Type, Is.EqualTo(JsonType.String));

        Assert.That((int)test["three"], Is.EqualTo(3));
        Assert.That((int)test["two"], Is.EqualTo(2));
        Assert.That((int)test["one"], Is.EqualTo(1));
        Assert.That((string)test["blast"], Is.EqualTo("off!"));
    }
开发者ID:grahamboree,项目名称:voorhees,代码行数:25,代码来源:JsonValueTest.cs

示例5: KVPCollection

    public void KVPCollection()
    {
        JsonValue test = new JsonValue() {
            {"one", 1},
            {"two", 2},
            {"three", 3},
        };

        test.Remove(new KeyValuePair<string, JsonValue>("one", 1));
        Assert.That(test.Count, Is.EqualTo(2));
        Assert.Throws<KeyNotFoundException>(() => test["one"].ToString());

        KeyValuePair<string, JsonValue>[] dest = new KeyValuePair<string, JsonValue>[2];
        test.CopyTo(dest, 0);
        for (int i = 0; i < 2; ++i) {
            Assert.That(test[dest[i].Key].Equals(dest[i].Value));
        }

        Assert.That(test.Contains(new KeyValuePair<string, JsonValue>("two", 2)));

        test.Add(new KeyValuePair<string, JsonValue>("four", 4));

        Assert.That(test.ContainsKey("four"), Is.True);
        Assert.That((int)test["four"], Is.EqualTo(4));
    }
开发者ID:grahamboree,项目名称:voorhees,代码行数:25,代码来源:JsonValueTest.cs

示例6: IDictionary

    public void IDictionary()
    {
        JsonValue test = new JsonValue() {
            {"one", 1},
            {"two", 2},
            {"three", 3}
        };

        Assert.That((int)test["one"], Is.EqualTo(1));
        test["one"] = 5;
        Assert.That((int)test["one"], Is.EqualTo(5));
        test["one"] = 1;

        var keys = test.Keys;
        Assert.That(keys.Count, Is.EqualTo(3));
        Assert.That(keys.Contains("one"), Is.True);
        Assert.That(keys.Contains("two"), Is.True);
        Assert.That(keys.Contains("three"), Is.True);

        var values = test.Values;
        Assert.That(values.Count, Is.EqualTo(3));
        var intvalues = values.Select(x => (int)x).ToArray();
        Array.Sort(intvalues);
        for (int i = 0; i < 3; i++) {
            Assert.That(intvalues[i], Is.EqualTo(i + 1));
        }

        test.Add("four", 4);
        Assert.That(test.Count, Is.EqualTo(4));
        Assert.That((int)test["four"], Is.EqualTo(4));

        JsonValue val;
        Assert.That(test.TryGetValue("one", out val), Is.True);
        Assert.That((int)val, Is.EqualTo(1));
        Assert.That(test.TryGetValue("seven", out val), Is.False);
        Assert.That(val, Is.Null);

        Assert.That(test.ContainsKey("four"), Is.True);
        test.Remove("four");
        Assert.That(test.Count, Is.EqualTo(3));
        Assert.That(test.ContainsKey("four"), Is.False);
    }
开发者ID:grahamboree,项目名称:voorhees,代码行数:42,代码来源:JsonValueTest.cs


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