dongpi0658 2013-09-28 16:34
浏览 106
已采纳

在PHP中将JSON字符串转换为关联数组

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. 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:

var_dump(json_decode(json_encode($theString), TRUE));

This dumps 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:

$toBeStored = json_encode(array("msg" => $value));
  • 写回答

1条回答

  • douyujun0152 2013-09-28 16:50
    关注

    Try this

    $var = '{"msg": "background1.jpg"}';
    
    var_dump($var);
    

    `

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services