[F] bug with json_foreach

QUOTE (Leftaf @ May 9 2015, 21:08) <{POST_SNAPBACK}>
Hi mp3taglover

fully right we need a

do {
    code block to be executed
}
while (condition);

does any one has some syntax for us?!

well, there is actually

Do ... While     S n     Execute the command surrounded by the two commands while S occurs on current position. The optional second parameter limits the execution of the loop to maximal n times.
Do
MoveLine 1
While "<td>"
Nesting of Do commands is not allowed.

but nesting is not allowed and the thing is you can't use this in json mode, because it's suitable only for NON json mode..

also there is another bug with json_foreach, you can't just use multiple nested json_foreach things if you go through some nested array.

e.g.:

# Credits per track
json_foreach "tracklist"
    json_select "type_"
    if "track"
        # ARTIST
        outputto "ARTISTTMP"
        json_select_many "artists" "name" ", "
                ifnot ""
            json_foreach "artists"
                json_select "name"
                ifnot ""        
                    say "<name>"
                    sayrest
                    say "</name>"
                endif
                json_select "anv"
                ifnot ""
                    say "<anv>"
                    sayrest
                    say "</anv>"
                endif
                json_select "join"
                ifnot ""
                    say "<join>"
                    sayrest
                    say "</join>"
                endif
            json_foreach_end
        else
            outputto "ARTISTTMP"
            sayoutput "BANDTMP"
        endif
        say "|"    

        outputto "CRTMP"
        json_select_many "extraartists" "name" ", "
        ifnot ""
            json_foreach "extraartists"            
                json_select "name"
                ifnot ""
                    say "<name>"
                sayrest
                    say "</name>"
                endif
                
                json_select "anv"
                ifnot ""
                    say "<anv>"
                    sayrest
                    say "</anv>"
                endif

                json_select "role"
                ifnot ""
                    say "<role>"
                    sayrest
                    say "</role>"
                endif
                
                json_select "tracks"
                ifnot ""
                    say "<tracks>"
                    sayrest
                    say "</tracks>"
                endif
            json_foreach_end
        endif
        say "|"
    endif
json_foreach_end

in this case only ARTISTTMP will be filled correctly with artists and CRTMP will be with root extraartists instead of the extraartists nested for each track, it's all because json_foreach_end goes to the root of the array after finishing i think instead of just going to the same element which was selected first.

the only workaround i've found is to put another json_foreach over tracklist again and put there json_foreach related to CRTMP:

# Credits per track
json_foreach "tracklist"
    json_select "type_"
    if "track"
        outputto "CRTMP"
        json_select_many "extraartists" "name" ", "
        ifnot ""
            json_foreach "extraartists"            
                json_select "name"
                ifnot ""
                    say "<name>"
                sayrest
                    say "</name>"
                endif
                
                json_select "anv"
                ifnot ""
                    say "<anv>"
                    sayrest
                    say "</anv>"
                endif

                json_select "role"
                ifnot ""
                    say "<role>"
                    sayrest
                    say "</role>"
                endif
                
                json_select "tracks"
                ifnot ""
                    say "<tracks>"
                    sayrest
                    say "</tracks>"
                endif
            json_foreach_end
        endif
        say "|"
    endif
json_foreach_end

there should be either some 'break' function to break out of cycle or jump/goto.