我需要直接使用mysql查询从json格式的表中获取值(在应用程序级别没有php等的后期处理)。表中的大部分字段都是整数,为记录构建json字符串并不难,但是有一列是text类型,my包含所有垃圾。
stringify是否可以使用文本类型的列数据来构建有效的json字符串?
查询:
select concat('var sp_json= [',
group_concat(
'{"sp_no":',sp_no,',
"sp_group_no":',sp_group_no,',
"sp_weight":',sp_weight,',
"dg_list":[',dg_list,'],
"comments":\'',coalesce(comments,''),'\'}'
order by sp_group_no
),
']') as sp_json
from sp_dg where pm_id=1 group by pm_id 这将输出javascript json对象等。
var sp_json=[{},,,]如果有内置的mysql函数,我需要使用内置的mysql函数来压缩comments。请分享你的想法。
发布于 2013-09-13 04:44:14
考虑将 function与this SO answer中的概念结合使用。
例如(SQL):
REPLACE(
REPLACE(
coalesce(comments,''),'\\','\\\\'
),'"','\\"'
)https://stackoverflow.com/questions/18778373
复制相似问题