What type of json string should be stored in mysql? Tell me why?
ask your bosses, in the project will often save a json format string to db, usually if it is expected to be a small amount of data to store varchar, if the data length is large to store text, is actually as a string to look at, but json itself is a kind of encoded data, php do json_encode if you do not specify parameters, the Chinese is garbled. In fact, this can not be regarded as an ordinary string, so I would like to see how the bosses usually store json data in db. What is the best reason? In addition, not to mention that the higher version of mysql supports the json type.
mysql has storage of type json. Above mysql5.7
I usually save the text type, because the field that stores the json string must be longer than the normal varchar. When you affirm the json_encode, you need to add parameters, otherwise it will be very embarrassing to parse the garbled code
\ uxxxx
is not garbled code. It's just that mysql will remove \
, and generally use varchar (n) note: n is not too big (256). If it is too large, consider building another table to remove the json.
json_encode ("Chinese", JSON_UNESCAPED_UNICODE)
I don't think json should be stored in the database. If you want to add text
is usually converted to a string with json_encode ().
if php does not specify parameters when doing json_encode, it is garbled in Chinese
generally do not view the data directly in the database, if this is really necessary, is it so difficult to add a parameter?
if it's really that difficult, is it so difficult to write a function that converts json to an array and an array to a string?
if php does not specify parameters when doing json_encode, it is garbled in Chinese
this is not a problem at all. In general, you don't need to go directly to the database to check the data
.