不要在生产中使用,而是尝试获取有效的 json 输出
$json = "{'403' : {'3' : { qin : 144, qout : 52}, '4' : { qin : 143, qout : 86}, '5' : { qin : 144, qout : 79}, '6' : { qin : 143, qout : 93}, '7' : { qin : 144, qout : 78} }" ;
$json = preg_replace("/'(\w+)'/", '$1', $json); //remove all single quote
$json = preg_replace("/\s*([a-zA-Z0-9_]+)/", ' "$1"', $json);
$json .= "}"; // Missing End
var_dump($json,json_decode($json));
输出
object(stdClass)[1]
public '403' =>
object(stdClass)[2]
public '3' =>
object(stdClass)[3]
public 'qin' => string '144' (length=3)
public 'qout' => string '52' (length=2)
public '4' =>
object(stdClass)[4]
public 'qin' => string '143' (length=3)
public 'qout' => string '86' (length=2)
public '5' =>
object(stdClass)[5]
public 'qin' => string '144' (length=3)
public 'qout' => string '79' (length=2)
public '6' =>
object(stdClass)[6]
public 'qin' => string '143' (length=3)
public 'qout' => string '93' (length=2)
public '7' =>
object(stdClass)[7]
public 'qin' => string '144' (length=3)
public 'qout' => string '78' (length=2