Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Fix parsing response for getting albums
Browse files Browse the repository at this point in the history
  • Loading branch information
canhlinh committed Sep 27, 2019
1 parent c4c30ee commit f35f7bb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
3 changes: 1 addition & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ func (client *Client) GetAlbums() (Albums, error) {
defer body.Close()

stringBody := BodyToString(body)
jsonBody := JsonBodyByScanLine(stringBody, 4, 5)

jsonBody := JsonBodyByScanLine(stringBody, 4, -1)
albumlResponse := NewAlbumlResponse(jsonBody)

albums, err := albumlResponse.Albums()
Expand Down
12 changes: 0 additions & 12 deletions file.txt

This file was deleted.

2 changes: 0 additions & 2 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ func (al *AlbumlResponse) Albums() (albums []*Album, err error) {

mainArray := al.getMainArray()

log.Warn(NewJSONString(mainArray))

for _, arr := range mainArray {
albumID, albumName := al.getAlbumInfo(arr.([]interface{}))
albums = append(albums, &Album{
Expand Down
10 changes: 9 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,17 @@ func JsonBodyByScanLine(s string, start, end int) string {
for scanner.Scan() {

text := scanner.Text()
text = strings.TrimSpace(text)

if i >= start && i <= end {
if i >= start {
b += text
if end == -1 && text == "]" {
break
}

if i == end {
break
}
}

i++
Expand Down

0 comments on commit f35f7bb

Please sign in to comment.