首页 > 解决方案 > json_encode breaks on image url

问题描述

I have a weird issue with json_encode. I have a table that I dump the user submissions in to for backup, but for some reason lately the image url breaks after a certain length. I'm not sure if it is because the photo is too big, but I don't see any fixes for this other than the JSON_PARTIAL_OUTPUT_ON_ERROR. Is there any way this can be fixed or some preventative for this?

{"task": [{
  "Hours": "12",
  "Photo": ["data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAADAKADAAQAAAA //It breaks right here

I only put a snippet of the base64 url to save space, but it breaks at the end.

标签: phpjson

解决方案


The most likely cause of your problem is that the database column you are inserting this data into has a limited size, and the JSON you are inserting is larger than that limit, so it is being truncated.

Solution is simple: change the database schema to allow longer values.


推荐阅读