欢迎 Stackoverflow 国家!我正在尝试使用 php 将 json 编码的字符串解码为 SQL 语句。
假设我有这样一个 json 编码的字符串 =>
$j = '{"groupOp":"AND","rules":[{"field":"id","op":"cn","data":"A"},{"field":"i_name","op":"cn","data":"B"}]}';
我想构建SQL WHERE子句(jqGrid 中的 filterToolbar 搜索需要),像这样 => " WHERE id LIKE %A% AND i_name LIKE %B%
" 等等。
我已经这样做了=>
$d = json_decode($j);
$filterArray = get_object_vars($d); // makes array
foreach($filterArray as $m_arr_name => $m_arr_key){
// here I can't made up my mind how to continue build SQL statement which I've mentioned above
}
任何想法如何做到这一点,初步感谢:)