php - remove double quotes from json encoded array -
$sql = "select column_type information_schema.columns table_name = 'mst_sim_data' , column_name = 'status'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $enumlist = explode(",", str_replace("'", '', substr($row['column_type'], 5, (strlen($row['column_type'])-6)))); foreach ($enumlist $key => $value) { $list["'$value'"] = $value; } return json_encode($list);
this returns following json string.
object {'instock': "instock", 'issued': "issued", 'soldout': "soldout"}
but need replace single quotes on double quotes , should this,
'instock': 'instock', 'issued': 'issued', 'soldout': 'soldout'}
how can this?
is goal break json output? json strings , properties must use "
quote.
i believe problem 2 fold
$list["'$value'"] = $value;
should$list["$value"] = $value;
andthe
"
s should left alone
if do wish mangle quotes (which means result not json), use result of
str_replace('"', "'", json_encode($list, json_hex_apos))
note json_hex_apos flag, prevent gross hack mutilating json-string embedded '
characters.
Comments
Post a Comment