Exemplo n.º 1
0
        public static SearchPage Parse(string jsonIn)
        {
            var page = new SearchPage();

            page.Results = new List <object>();
            var obj = JsonDocument.Parse(jsonIn).RootElement;

            foreach (var item in obj.EnumerateObject())
            {
                switch (item.Name)
                {
                case "pagination":
                    page.Pagination = Paging.Create(item.Value);
                    break;

                default:
                    foreach (var releaseObj in item.Value.EnumerateArray())
                    {
                        foreach (var releaseItem in releaseObj.EnumerateObject())
                        {
                            switch (releaseItem.Name)
                            {
                            case "release":
                                page.Results.Add(ReleaseStub.Parse(releaseObj));
                                break;

                            case "master":
                                page.Results.Add(MasterStub.Parse(releaseObj));
                                break;

                            case "artist":
                                page.Results.Add(ArtistStub.Parse(releaseObj));
                                break;

                            case "label":
                                page.Results.Add(LabelStub.Parse(releaseObj));
                                break;

                            default:
                                throw new Exception(String.Format("Unknown Object Type when parsing Artist Releases page: {0}", releaseItem.Name));
                            }
                        }
                    }
                    break;
                }
            }

            return(page);
        }
Exemplo n.º 2
0
        public static LabelStub Parse(JsonElement element)
        {
            var item = new LabelStub();

            foreach (var obj in element.EnumerateObject())
            {
                switch (obj.Name)
                {
                case "name":
                    item.Name = obj.Value.GetString();
                    break;

                case "id":
                    item.Id = obj.Value.GetInt32();
                    break;

                case "resource_url":
                    item.ResourceURI = obj.Value.GetString();
                    break;

                case "catno":
                    item.CatalogNo = obj.Value.GetString();
                    break;

                case "entity_type_name":
                    item.EntityTypeName = obj.Value.GetString();
                    break;

                case "entity_type":
                    item.EntityType = obj.Value.GetString();
                    break;

                case "type":
                    //Don't Care
                    break;

                default:
                    throw new Exception(string.Format("Unrecognised parameter when creating the Discogs LabelStub Object. Parameter is: {0}", obj.Name));
                }
            }

            return(item);
        }