有没有一种优雅的方式来转换这个 JSON 字符串:
{
"my_index": 1,
"first_name": "John",
"last_name": "Smith",
"address": {
"address1": "123 Main St",
"address2": "PO Box 123",
"city": "Anywhere",
"state": "CA",
"zip": 12345
}
}
到这个 PHP 代码块:
$data = array();
$data["my_index"] = 1;
$data["first_name"] = "John";
$data["last_name"] = "Smith";
$data["address"] = array();
$data["address"]["address1"] = "123 Main St";
$data["address"]["address2"] = "PO Box 123";
$data["address"]["city"] = "Anywhere";
$data["address"]["state"] = "CA";
$data["address"]["zip"] = 12345;
基本上,构建代码以粘贴到其他内容中。我不想要一个 json_decode() 的对象。我真的想以一串 PHP 代码结束,而不是一个 PHP 对象!
倚天杖
弑天下