[英]Converting JSON string to Associative array in PHP
What I'm trying to Do is so simple yet everything I tries had failed. 我想做的事情很简单,但是我尝试的所有事情都失败了。 I have the following string:
"{"msg":"background1.jpg"}"
, and I want to convert it to an array to access the msg
value. 我有以下字符串:
"{"msg":"background1.jpg"}"
,我想将其转换为数组以访问msg
值。 this should simply be done like so(or so I've thought): 这应该像这样简单地完成(或者我想过):
$theString = "{"msg":"background1.jpg"}";
var_dump(json_decode($theString, TRUE));
The vr_dump()
is dumping NULL
, also tried: vr_dump()
正在转储NULL
,也尝试过:
var_dump(json_decode(json_encode($theString), TRUE));
This dumps string(45) "{"msg":"background1.jpg"}"
这将转储
string(45) "{"msg":"background1.jpg"}"
and tried many many more things, but all failed. 并尝试了许多其他尝试,但都失败了。 Any thought please.
有什么想法请。
EDIT: 编辑:
I'm getting the json string from database, where i have previously stored like so: 我从数据库中获取json字符串,我以前已经将其存储在这样的数据库中:
$toBeStored = json_encode(array("msg" => $value));
Try this 尝试这个
$var = '{"msg": "background1.jpg"}';
var_dump($var);
` `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.