[PHP] replaces JSON model data with JSON data
{data:[{code: "Spot gold", Newprice: "1662.3", Hight: "0", Low: "0", Buy: "1662.3", Sell: "r1663.3", Zhang: "r4.75", Date: " 4:59:40 ", Open:" 0 ", Close:" 1657.55 "}, {code:" Hong Kong Gold ", Newprice:" 15384 ", Hight:" 0 ", Low:" 0 ", Buy:" 15384 ", Sell:" r15390 ", Zhang: "R44", Date: "2:59:55", Open: "0", Close: "15340"}, {code: "Spot Silver", Newprice: "31.25", Hight: "0", Low: "0", Buy: "31.25" , Sell: "r31.31", Zhang: "r0.17", Date: "4:56:10", Open: "0", Close: "31.08"}, {code: "Spot Platinum", Newprice: "1566.75", Hight: "0", Low: "0", Buy: "1566.75", Sell: "r1576.75", Zhang: "r2.01", Date: "3:29:35", Open: "0", Close: "1564.74"}, {code: "Spot Palladium", Newprice: "677.23", Hight: "0", Low: "0", Buy: "677.23", Sell: "r684.23", Zhang: "r9.54", Date: "3:29:35", Open: "0", Close: " 667.69 "}]}
Everyone, this is a model with a JSON data, but the key name does not have quotation marks, so Json_decode will consider it an illegal JSON data format. Now use the regular to replace it with quotation marks.
/(? <={|,) [^:\s]*/is, currently can match a two-dimensional data, but replace the words, no, it must be a one-dimensional array.
Ask you heroes.
------Solution--------------------
PHP Code
------Solution--------------------
$json =preg_replace ('/(, |,?\s*?{) \b (\w+):/', ' $ "$": ', $json);
Print_r (Json_decode ($json, true));
------Solution--------------------
or the Boss Mighty
2 Floor modification is ok ({|,) ([^:\s]*) (? =:)
discuss
Upstairs, very good, is the result I want.
Would you like to ask: with regular (? <={|,) [^:\s]* (? =:) this way, no??
------Solution--------------------
discuss
Upstairs, very good, is the result I want.
Would you like to ask: with regular (? <={|,) [^:\s]* (? =:) this way, no??