【发布时间】:2016-10-12 01:18:54
【问题描述】:
我有一个存储在 MYSQL 数据库中的 JSON 字符串。示例:
stdClass Object (
[product] => stdClass Object
(
[sold_individually] =>
[regular_price] =>
[managing_stock] => 1
[sku] => 0001
[title] => Sample title
[reviews_allowed] => 1...
等等
我已经使用 utf8_encode() 来转换它。然后如何将其转换为 PHP 数组以便我可以使用它?
编辑 1
我现在在发布到数据库时使用了 json_encode()。我还不得不使用 addSlashes(),因为我遇到了一些值的格式问题。
当我现在提取数据时,它看起来像:
"{\"product\": {\"sold_individually\": false, \"regular_price\": \"\", \"managing_stock\": true, \"sku\": \"W-C-6500\", \"title\": \"Sample title\"...
如何提取“title”的值?我还应该使用 str_replace() 来摆脱 \ 问题吗?
【问题讨论】:
-
你试过PHP的“json_decode”函数吗?
-
你试过 $array = json_decode($json,1); ?
-
是的,我尝试过使用 json_decode() 并且得到了 NULL。我需要将字符串转换为对象吗?