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 ArtistStub Parse(JsonElement element)
        {
            var item = new ArtistStub();

            foreach (var obj in element.EnumerateObject())
            {
                switch (obj.Name)
                {
                case "uri":
                    item.WebURL = "https://discogs.com" + obj.Value.GetString();
                    break;

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

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

                case "role":
                    item.Role = obj.Value.GetString();
                    break;

                case "thumb":
                    item.ThumbnailURL = obj.Value.GetString();
                    break;

                case "title":
                    item.Title = obj.Value.GetString();
                    break;

                case "year":
                    item.Year = obj.Value.GetInt32();
                    break;

                case "format":
                    item.Format = obj.Value.GetString();
                    break;

                case "label":
                    item.Label = obj.Value.GetString();
                    break;

                case "user_data":
                    item.UserData = UserData.Parse(obj.Value);
                    break;

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

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

            return(item);
        }