如何在PHP中解析此JSON? [英] How to parse this JSON in PHP?

查看:85
本文介绍了如何在PHP中解析此JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它存储在MongoDB中,并通过json_decode.

It's stored inside MongoDB and passed to my view file with json_decode.

使用PHP,如何从内部获取值?

Using PHP, how can I grab the values from within?

"environment" : {
            "_id" : "QU",
            "name" : "QA Unstable",
            "streams" : "unstable",
            "hosts" : [
                    "deployclient1",
                    "deployclient2"
            ]
}

推荐答案

由于您已经知道json_decode,因此现在可以实际回答问题了:

Now to actually answer the question since you already know of json_decode:

使用PHP,如何从内部获取值?

Using PHP, how can I grab the values from within?

json_decode会将JSON字符串评估为PHP中的一个对象(默认情况下),这意味着您可以使用基本的动态访问语法来获取您的值,即获取_id:

json_decode will evaluate the JSON string into a object in PHP (by default) which means you can use basic dynamic accession syntax to get to your values, i.e. to get _id:

$object->environment->_id;

或主持人:

$object->environment->hosts[0]

这将返回:deployclient1

这篇关于如何在PHP中解析此JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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