douju9272
2017-01-09 08:18
浏览 264
已采纳

将PHP字符串转换为JSON数组(键:值)

I have the following string that I receive from an API call:

a = "{
      "option1"=>"Color",
      "attribute1"=>{0=>"Black", 1=>"White",2=>"Blue"},
      "option2"=>"Size",
      "attribute2"=>{0=>"S", 1=>"L",2=>"M"}
}"

I would like to convert it to a JSON array; So, I have tried JSON_encode(), but it returns the following string:

""{\"option1\"=>\"Color\",\"attribute1\"=>{0=>\"Black\", 1=>\"White\",2=>\"Blue\"},\"option2\"=>\"Size\",\"attribute2\"=>{0=>\"S\", 1=>\"L\",2=>\"M\"}}"" 

Could you please advise me on how to achieve what i want.

Thanks

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

我从API调用中收到以下字符串:

   a =“{
”option1“=>”Color“,
”attribute1“=> {0 =>”黑色“,1 =>”白色“,2 =>”蓝色 “},
”option2“=>”尺寸“,
”attribute2“=> {0 =>”S“,1 =>”L“,2 =>”M“} 
  }“
   
 
 

我想将其转换为JSON数组; 所以,我尝试了 JSON_encode(),但它返回以下字符串:

 “”{\“option1 \”=> \“  Color \“,\”attribute1 \“=> {0 => \”Black \“,1 => \”White \“,2 => \”Blue \“},\”option2 \“=  > \“尺寸\”,\“attribute2 \”=> {0 => \“S \”,1 => \“L \”,2 => \“M \”}}“”  
   
 
 

请告诉我如何实现我的目标。

谢谢

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题