Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json parsing #348

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions frontend/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export function secIntoMinSec(timeInSeconds) {
export const fetchSongData = async (songName, setCurrSong) => {
try {
const response = await axios.get(`https://spring-music-player-3hyj.vercel.app/search?songs=${encodeURIComponent(songName)}`);
const data = await response.json();
setCurrSong(data[0]);
const data = await response.text();
const jsonData = JSON.parse(data);
setCurrSong(jsonData[0]);
} catch (error) {
console.error("There was a problem with the fetch operation:", error);
}
Expand All @@ -20,8 +21,9 @@ export const fetchSongData = async (songName, setCurrSong) => {
export const fetchSonsgByName = async (songName, setSongs, count = 6) => {
try {
const response = await axios.get(`https://spring-music-player-3hyj.vercel.app/search?songs=${encodeURIComponent(songName)}`);
const data = await response.json();
const songs = data.slice(0, count);
const data = await response.text();
const jsonData = JSON.parse(data);
const songs = jsonData.slice(0, count);
setSongs(songs);
} catch (error) {
console.error("There was a problem with the fetch operation:", error);
Expand All @@ -31,8 +33,9 @@ export const fetchSonsgByName = async (songName, setSongs, count = 6) => {
export const fetchTopSongs = async (setTopSongs, count = 6) => {
try {
const response = await axios.get("https://spring-music-player-3hyj.vercel.app/api/search?songs=top songs");
const data = await response.json();
const topSongs = data.slice(0, count);
const data = await response.text();
const jsonData = JSON.parse(data);
const topSongs = jsonData.slice(0, count);
setTopSongs(topSongs);
} catch (error) {
console.error("There was a problem with the fetch operation:", error);
Expand Down
Loading