在PHP上进行JSON编码和解码 [英] JSON encode and decode on PHP

查看:110
本文介绍了在PHP上进行JSON编码和解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编码了JSON输出.

I have JSON output encoded.

$responseJSON
{"status":1,"content":{"sessionid":"4c86cf1acac07811db6ec670e0b9cdd2"}}

现在我对此进行解码

$decoded=json_decode($responseJSON);

print_r($decoded)

我知道

stdClass Object (
  [status] => 1 
  [content] => stdClass Object ( 
    [sessionid] => 4c86cf1acac07811db6ec670e0b9cdd2 
  ) 
) 

我不想这样解码.

如何在没有这些stdClass标签的情况下解码为普通数组?

how do I decode to an normal array without those stdClass tag?

推荐答案

没有足够的代表来评论其他人的评论

Don't have enough rep to comment on other peoples comments

在处理完信息后获取信息

To get the info out after you've processed it with

$decoded = json_decode( $responseJSON, TRUE );

您可以照常访问其中的所有信息.

You can access all the information inside of it as normal. do a

var_dump($decoded);

以防万一它增加了您不期望的水平 然后照常进行

just incase it add's levels you wouldn't expect Then just proceed as usual

echo $decoded['status']
echo $decoded['content']['sessionid']

这篇关于在PHP上进行JSON编码和解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆