Пример #1
0
        private void createListOfDogs(JsonArray dogJson)
        {
            foreach (var item in dogJson)
            {
                // get the object (like the sender)
                var obj = item.GetObject();
                // create new dog object to map to
                clsDog dog = new clsDog();

                // get each key value pair and sort it to the
                // appropriate elements of the class
                foreach (var key in obj.Keys)
                {
                    IJsonValue value;
                    if (!obj.TryGetValue(key, out value))
                    {
                        continue;
                    }

                    switch (key)
                    {
                    case "breed":
                        dog.breed = value.GetString();
                        break;

                    case "origin":
                        dog.origin = value.GetString();
                        break;

                    case "category":
                        dog.category = value.GetString();
                        break;

                    case "activity":
                        dog.activity = value.GetString();
                        break;

                    case "grooming":
                        dog.grooming = value.GetString();
                        break;

                    case "image":
                        dog.imgBreed = value.GetString();
                        break;
                    } // end switch
                }     // end foreach (var key in obj.Keys)

                _mylist.Add(dog);
            } // end foreach (var item in array)
        }
Пример #2
0
        private void createListOfDogs(JsonArray dogJson)
        {
            foreach (var item in dogJson)
            {
                // get the object (like the sender)
                var obj = item.GetObject();
                // create new dog object to map to
                clsDog dog = new clsDog();

                // get each key value pair and sort it to the 
                // appropriate elements of the class
                foreach (var key in obj.Keys)
                {
                    IJsonValue value;
                    if (!obj.TryGetValue(key, out value))
                        continue;

                    switch (key)
                    {
                        case "breed":
                            dog.breed = value.GetString();
                            break;
                        case "origin":
                            dog.origin = value.GetString();
                            break;
                        case "category":
                            dog.category = value.GetString();
                            break;
                        case "activity":
                            dog.activity = value.GetString();
                            break;
                        case "grooming":
                            dog.grooming = value.GetString();
                            break;
                        case "image":
                            dog.imgBreed = value.GetString();
                            break;
                    } // end switch
                } // end foreach (var key in obj.Keys)

                _mylist.Add(dog);

            } // end foreach (var item in array)
        }