Beispiel #1
0
        public override void ParseJObject(Object obj)
        {
            IPosel posel = obj as IPosel;
            List <BiuroPoselskie> biura = DataObjectParser.ParseJArrayToList <BiuroPoselskie> (this.JsonObject as JArray);

            posel.Biura.AddRange(biura);
        }
        public async Task <T> GetJsonObjectAsync(RequestParamsHandler request)
        {
            var response = await ConnectionProvider.GetHttpClient().GetAsync(request.GetRequest());

            response.EnsureSuccessStatusCode();

            string content = await response.Content.ReadAsStringAsync();

            /*
             * JToken obj;
             * bool hasValue = JObject.Parse(content).TryGetValue ("object", out obj);
             * if (!hasValue) //jeżeli nie istnieje element object w odpowiedzi json
             *      throw new NoObjectJsonElementException ();
             * if(obj.Type == JTokenType.Boolean) //jeżeli element object z odpowiedzi json ma typ boolean (nie muszę sprawdzać wartości, wystarczy wiedza na temat typu)
             *      throw new ObjectJsonBooleanElementException();
             *
             * T finalObject = DataObjectParser.ParseJObjectToType<T> (obj as JObject);
             */

            JObject obj         = JObject.Parse(content);
            T       finalObject = DataObjectParser.ParseJObjectToType <T>(obj);

            if (request.Layers.Count > 0)
            {
                //dodatkowe warstwy
                foreach (ILayer layer in request.Layers)
                {
                    layer.AssignContent(obj);
                    layer.ParseJObject(finalObject as Object);
                }
            }

            return(finalObject);
        }
        public async Task <List <T> > GetJsonArrayAsync(RequestParamsHandler request)
        {
            var response = await ConnectionProvider.GetHttpClient().GetAsync(request.GetRequest());

            response.EnsureSuccessStatusCode();

            string content = await response.Content.ReadAsStringAsync();

            /*
             * JToken obj;
             * bool hasValue = JObject.Parse (content).TryGetValue ("search", out obj);
             * if (!hasValue) //jeżeli nie istnieje element search w odpowiedzi json
             *      throw new NoObjectJsonElementException ();
             * if(obj.Type == JTokenType.Boolean) //jeżeli element search z odpowiedzi json ma typ boolean (nie muszę sprawdzać wartości, wystarczy wiedza na temat typu)
             *      throw new ObjectJsonBooleanElementException();
             */

            JArray dataobjects = (JArray)JObject.Parse(content) ["Dataobject"];

            List <T> list = new List <T> (dataobjects.Count);

            foreach (var item in dataobjects)
            {
                T temp = default(T);

                if (request.Contexts.Count > 0)
                {
                    foreach (IContext context in request.Contexts)
                    {
                        context.AssignContent(item as JObject);
                        temp = (context.ParseJObject() as T);
                    }
                }
                else
                {
                    temp = DataObjectParser.ParseJObjectToType <T> (item as JObject);
                }
                list.Add(temp);
            }
            return(list);
        }