Вопрос

I'm opening a JSON file and decoding the content of it, so I can insert the content into my database using MySQL:

[{"publisher": "some publisher", "img": "url to image", "title": "some title", "platform": "some platform", "year": "2012", "genre": "some genre", "desc": "this is the description", "id": "1", "developer": "some developer"}]

This is just 1 one of the entries in the file. The JSON file contains more than 10000 of these. I'm getting internal server while using json_decode($file). Reading the file and var_dump($file) works just fine. So my question is, is this a good JSON file? Or how can I decode and insert it in the database?

Thanks in advance.

Это было полезно?

Решение

There is nothing wrong with that fragment of JSON.

You should look at the specific error message reported (either by running the PHP outside a web server, or by looking in the error logs for it). Internal Server Error just means "Something went wrong, an admin/developer should look at the logs".

Другие советы

If the file is so big, it could be, that php runs out of memory or execution time, but as said before, start by looking in log files.

Again you need errors but unlike the others stating look at log file i do understand some times you can't certain Hosts for example,

To enable your script to show the error use

error_reporting(2047); 
ini_set("display_errors",1);

If your are getting a memory error use ini_set('memory_limit', '128M');

This should allow it if not or an error is throw because your calling ini_set you need to contact your server host and ask them to allow more memory

I had this same error. I fixed it by changing my json_decode($whatever) code to json_decode($whatever, TRUE). I hope this helps someone.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top