Пример #1
0
        internal static Snak newFromArray(JsonObject data)
        {
            if (data.get("snaktype") == null || data.get("property") == null)
            {
                throw new ArgumentException("Invalid Snak serialization", "data");
            }
            var dataValue = data.get("datavalue");

            if (dataValue != null)
            {
                return(new Snak(
                           data.get("snaktype").asString(),
                           EntityId.newFromPrefixedId(data.get("property").asString()),
                           DataValueFactory.newFromArray(dataValue.asObject())
                           ));
            }
            else
            {
                return(new Snak(
                           data.get("snaktype").asString(),
                           EntityId.newFromPrefixedId(data.get("property").asString()),
                           null
                           ));
            }
        }
Пример #2
0
        protected virtual void fillData(JsonObject data)
        {
            if (data.get("id") != null)
            {
                this.id = EntityId.newFromPrefixedId(data.get("id").asString());
            }
            if (data.get("lastrevid") != null)
            {
                this.lastRevisionId = data.get("lastrevid").asInt();
            }
            JsonValue returnedLabels = data.get("labels");

            if ((returnedLabels != null) && (returnedLabels.isObject()))
            {
                if (data.get("labels") != null)
                {
                    labels.Clear();
                    foreach (JsonObject.Member member in returnedLabels.asObject())
                    {
                        JsonObject obj = member.value.asObject();
                        this.labels.Add(obj.get("language").asString(), obj.get("value").asString());
                    }
                }
            }
            JsonValue returnedDescriptions = data.get("descriptions");

            if ((returnedDescriptions != null) && (returnedDescriptions.isObject()))
            {
                descriptions.Clear();
                foreach (JsonObject.Member member in returnedDescriptions.asObject())
                {
                    JsonObject obj = member.value.asObject();
                    this.descriptions.Add(obj.get("language").asString(), obj.get("value").asString());
                }
            }
            JsonValue returnedAliases = data.get("aliases");

            if ((returnedAliases != null) && (returnedAliases.isObject()))
            {
                // strange - after save an empty array is returned, whereas by a normal get the fully alias list is returned
                aliases.Clear();
                foreach (JsonObject.Member member in returnedAliases.asObject())
                {
                    List <String> list = new List <String>();
                    foreach (JsonValue value in member.value.asArray())
                    {
                        list.Add(value.asObject().get("value").asString());
                    }
                    this.aliases.Add(member.name, list);
                }
            }
            JsonValue returnedClaims = data.get("claims");

            if ((returnedClaims != null) && (returnedClaims.isObject()))
            {
                claims.Clear();
                foreach (JsonObject.Member member in returnedClaims.asObject())
                {
                    Dictionary <String, Claim> list = new Dictionary <String, Claim>();
                    foreach (JsonValue value in member.value.asArray())
                    {
                        Claim claim = Claim.newFromArray(this, value.asObject());
                        list.Add(claim.internalId, claim);
                    }
                    this.claims.Add(member.name, list);
                }
            }
        }