在PHP变量中获取JSON对象的值 [英] Get value of JSON object in PHP variable

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

问题描述

我有以下JSON对象:

I have the following JSON object:

[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
   0: Object
      category: Object
         0: "Value"

我想知道如何在PHP变量中获得值". 我以为category [0]会做到这一点,但是我得到了以下内容,而不是"Value":

I was wondering how I could get 'Value' in a variable in PHP. I thought category[0] would just do it but I get the following instead of 'Value':

 __proto__: Object 

我该怎么办?

推荐答案

您必须将JSON字符串转换为关联数组,这是通过json_decode()将第二个参数设置为true来完成的.

You have to converts the JSON string into associative array, which is done by json_decode() with second parameter set as true.

$var = json_decode($json, true); 
$value = $var['0']['category']['0'];

这篇关于在PHP变量中获取JSON对象的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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