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

图片转代码服务由CSDN问答提供 功能建议

我正在尝试做的事情很简单,但我尝试的一切都失败了。 我有以下字符串:“{”msg“:”background1.jpg“}”,我想将其转换为数组以访问 msg 值。 这应该只是这样(或者我认为):

  $ theString =“{”msg“:”background1.jpg“}”; 
 \  nvar_dump(json_decode($ theString,TRUE)); 
   
 
 

vr_dump()正在转储 NULL , 还试过:

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

此转储 string(45)“{”msg“:”background1.jpg“}”

并尝试了很多其他内容,但都失败了。 请任何想法。

编辑:

我从数据库中获取json字符串,我之前存储过这样的字符串:

  $ toBeStored = json_encode(array(“msg”=> $ value)); 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题