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);
    

    `

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料