parsing the json response: now it is based on a while loop