I have a column in mysql table jsonvalues
type blob I'm storing below raw json values into this field
我在mysql表中有一个列jsonvalues类型blob我将原始json值存储到此字段中
{"name":"john","mob":"23434"}
but when I'm fetching from the db in node js, json values are changing to
但是当我从节点js中的db中获取时,json值正在变为
{"type":"Buffer","data":[34,123,
I want to display the values as raw json in html column, what am I doing wrong?
我想在html列中将值显示为原始json,我做错了什么?
2 个解决方案
#1
0
You can easily store JSON into mysql table - just serialize JSON to string (const jsonString = JSON.stringify(jsonObject);
).
您可以轻松地将JSON存储到mysql表中 - 只需将JSON序列化为字符串(const jsonString = JSON.stringify(jsonObject);)。
Thus suitable mysql field types are VARCHAR, TEXT or bigger text types.
因此合适的mysql字段类型是VARCHAR,TEXT或更大的文本类型。
De-serialize stored string to get Json object back (const jsonObject = JSON.parse(jsonString);
). Then you can use your raw json whatever you want. Hope that helps..
反序列化存储的字符串以获取Json对象(const jsonObject = JSON.parse(jsonString);)。然后你可以随意使用你的原始json。希望有所帮助..
#2
0
i found the answer myself, i have changed the mysql field type from blob to varchar
and it is displaying on the result in node js and the same in html also.
我自己找到了答案,我已经将mysql字段类型从blob更改为varchar,它在节点js中显示结果,在html中也显示相同。
#1
0
You can easily store JSON into mysql table - just serialize JSON to string (const jsonString = JSON.stringify(jsonObject);
).
您可以轻松地将JSON存储到mysql表中 - 只需将JSON序列化为字符串(const jsonString = JSON.stringify(jsonObject);)。
Thus suitable mysql field types are VARCHAR, TEXT or bigger text types.
因此合适的mysql字段类型是VARCHAR,TEXT或更大的文本类型。
De-serialize stored string to get Json object back (const jsonObject = JSON.parse(jsonString);
). Then you can use your raw json whatever you want. Hope that helps..
反序列化存储的字符串以获取Json对象(const jsonObject = JSON.parse(jsonString);)。然后你可以随意使用你的原始json。希望有所帮助..
#2
0
i found the answer myself, i have changed the mysql field type from blob to varchar
and it is displaying on the result in node js and the same in html also.
我自己找到了答案,我已经将mysql字段类型从blob更改为varchar,它在节点js中显示结果,在html中也显示相同。