Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
json_decode JSON_ERROR_UTF8 on one API call, passes validation test when copy/pasted and all other API calls work fine

I am working a project which uses theyworkforyou's API (UK-based political data organisation) and specifically the function getMPInfo() which takes the ID of the MP (member of parliament) and returns lots of data about them (when they came into office, how long they've been in office, etc.)

The problem I'm having is that the following line of code works on every ID I've tried except one (that I've found so far):

var_dump(json_decode(file_get_contents("http://www.theyworkforyou.com/api/getMPInfo?key=MY_KEY&id=SOME_ID&output=js")));

if I do a json_last_error() call I get JSON_ERROR_UTF8 on that one ID.

The ID in question is 10999. You can try it out in the docs section of their api portal here.

If I just output http://www.theyworkforyou.com/api/getMPInfo?key=MY_KEY&id=10999&output=js to the screen and copy and paste it into a json validator, it seems to pass the test fine. I've tried with 3 so far and none have found a fault.

Can anyone see what the problem is or what I've potentially done wrong? It could be a fault of the API of course but I've never had a problem with any json parsing errors using this API in the past (I've been using it with all MPs in the past for a few years now), it works for all other MP IDs I've tried it with and like I said, it seems to be valid json from the point of view of the online validators.

Thank you for your time.

P.S. I'm not sure how you could replicate my problem without an API key so here is a link to the api portal homepage where you can sign up for an API key.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

JSON_ERROR_UTF8 error means

Malformed UTF-8 characters, possibly incorrectly encoded

json_encode says

All string data must be UTF-8 encoded

So you just need to utf8_encode your input before passing it to json_encode.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda