简体   繁体   English

解码json文件时发生内部服务器错误

[英]Internal server error while decoding a json file

I'm opening a JSON file and decoding the content of it, so I can insert the content into my database using MySQL: 我正在打开一个JSON文件并对其内容进行解码,因此可以使用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. JSON文件包含超过10000个。 I'm getting internal server while using json_decode($file) . 我在使用json_decode($file)时正在获取内部服务器。 Reading the file and var_dump($file) works just fine. 读取文件和var_dump($file)很好。 So my question is, is this a good JSON file? 所以我的问题是,这是一个好的JSON文件吗? Or how can I decode and insert it in the database? 或者如何解码并将其插入数据库?

Thanks in advance. 提前致谢。

如果文件太大,则可能是php用完了内存或执行时间,但是如前所述,首先要查看日志文件。

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'); 如果您遇到内存错误,请使用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 如果没有,这应该允许它,否则将引发错误,因为调用ini_set时需要联系服务器主机并要求他们允许更多的内存

I had this same error. 我有同样的错误。 I fixed it by changing my json_decode($whatever) code to json_decode($whatever, TRUE) . 我通过将json_decode($whatever)代码更改为json_decode($whatever, TRUE)来修复了它。 I hope this helps someone. 我希望这可以帮助别人。

There is nothing wrong with that fragment of JSON. 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). 您应该查看所报告的特定错误消息(通过在Web服务器外部运行PHP或在错误日志中查找它)。 Internal Server Error just means "Something went wrong, an admin/developer should look at the logs". 内部服务器错误仅表示“出现问题,管理员/开发人员应查看日志”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM