Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
Error de JSON Parse: identificador inesperado "indefinido"

Acabo de cambiar a una Mac hoy y noté que JSON.parse que funciona en otros navegadores arroja este error en Safari.

 Unhandled Promise Rejection: SyntaxError: JSON Parse error: Unexpected identifier "undefined"

Esta es la respuesta JSON de mi código PHP

 {"dataPointsX": "[\"31 Jan\",\"01 Feb\",\"02 Feb\",\"03 Feb\",\"04 Feb\",\"05 Feb\",\"06 Feb\"]", "dataPointsY": "[\"0\",\"0\",\"7287\",\"24572\",\"30657\",\"27865\",\"0\"]", "dataPoints2Y": "[\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]"}

Este es mi código Javascript

 $.get('chartdata.php', async function (res) { console.log(res) var res = JSON.parse(res); });

Por favor ayuda

ACTUALIZAR

He actualizado mi PHP para hacer eco de esto

 {"dataPointsX":["31 Jan","01 Feb","02 Feb","03 Feb","04 Feb","05 Feb","06 Feb"],"dataPointsY":["0","0","7287","24572","30632","27820","0"],"dataPoints2Y":["0","0","0","0","0","0","0"]}

Funciona en Chrome, Safari sigue arrojando este error.

 Unhandled Promise Rejection: SyntaxError: JSON Parse error: Unexpected identifier "undefined"

Console.log(JSON.parse(res)) muestra esto en Chrome

 dataPoints2Y: (7) ['0', '0', '0', '0', '0', '0', '0'] dataPointsX: (7) ['31 Jan', '01 Feb', '02 Feb', '03 Feb', '04 Feb', '05 Feb', '06 Feb'] dataPointsY: (7) ['0', '0', '7287', '24572', '30489', '27744', '0'] [[Prototype]]: Object
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que su código PHP es contenido de codificación JSON que ya está codificado en JSON, tal vez algo como esto:

 $points = ['31 Jan', '01 Feb', '03 Feb']; echo json_encode(['dataPointsX' => json_encode($points)]);

Esto produce la cadena entre comillas extrañas:

 {"dataPointsX":"[\"31 Jan\",\"01 Feb\",\"03 Feb\"]"}

Solo desea llamar a json_encode() una vez:

 $points = ['31 Jan', '01 Feb', '03 Feb']; echo json_encode(['dataPointsX' => $points]);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!