<small id='1kRG5'></small><noframes id='1kRG5'>

<legend id='1kRG5'><style id='1kRG5'><dir id='1kRG5'><q id='1kRG5'></q></dir></style></legend>

      <bdo id='1kRG5'></bdo><ul id='1kRG5'></ul>

      <i id='1kRG5'><tr id='1kRG5'><dt id='1kRG5'><q id='1kRG5'><span id='1kRG5'><b id='1kRG5'><form id='1kRG5'><ins id='1kRG5'></ins><ul id='1kRG5'></ul><sub id='1kRG5'></sub></form><legend id='1kRG5'></legend><bdo id='1kRG5'><pre id='1kRG5'><center id='1kRG5'></center></pre></bdo></b><th id='1kRG5'></th></span></q></dt></tr></i><div id='1kRG5'><tfoot id='1kRG5'></tfoot><dl id='1kRG5'><fieldset id='1kRG5'></fieldset></dl></div>
    1. <tfoot id='1kRG5'></tfoot>
    2. 用 PHP 解析 JSON 数据

      时间:2023-09-23

        <bdo id='TxjDV'></bdo><ul id='TxjDV'></ul>

      • <small id='TxjDV'></small><noframes id='TxjDV'>

              <tbody id='TxjDV'></tbody>
            <tfoot id='TxjDV'></tfoot>
            <i id='TxjDV'><tr id='TxjDV'><dt id='TxjDV'><q id='TxjDV'><span id='TxjDV'><b id='TxjDV'><form id='TxjDV'><ins id='TxjDV'></ins><ul id='TxjDV'></ul><sub id='TxjDV'></sub></form><legend id='TxjDV'></legend><bdo id='TxjDV'><pre id='TxjDV'><center id='TxjDV'></center></pre></bdo></b><th id='TxjDV'></th></span></q></dt></tr></i><div id='TxjDV'><tfoot id='TxjDV'></tfoot><dl id='TxjDV'><fieldset id='TxjDV'></fieldset></dl></div>

          1. <legend id='TxjDV'><style id='TxjDV'><dir id='TxjDV'><q id='TxjDV'></q></dir></style></legend>
                本文介绍了用 PHP 解析 JSON 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我已多次解析 JSON 数据,但由于某种原因,无法找到嵌套数据时要使用的正确语法.我正在尝试从此 JSON 解析资产",但无论我尝试什么,都会继续获得为 foreach() 提供的无效参数.

                I have parsed JSON data numerous times but for some reason cannot find the correct syntax to use when the data is nested. I am trying to parse the "assets" from this JSON but continue to get a invalid argument supplied foreach() regardless of what I try.

                   "3435":{
                      "name":"COLO-1014-SJ1",
                      "nickname":"US-SJC-004",
                      "type":"Colocated Server",
                      "location":"San Jose:55 S Market",
                      "assets":{
                         "CPU":[
                            {
                               "model":"Intel E3 1270"
                            }
                         ],
                         "Hard Drives":[
                            {
                               "model":"Western Digital 500GB RE4 ABYX SATA"
                            },
                            {
                               "model":"Western Digital 500GB RE4 ABYX SATA"
                            },
                            {
                               "model":"Kingston 240GB SSD"
                            }
                         ],
                         "RAM":[
                            {
                               "model":"Super Talent 4GB DDR3 1333 ECC"
                            },
                            {
                               "model":"Super Talent 4GB DDR3 1333 ECC"
                            },
                            {
                               "model":"Super Talent 4GB DDR3 1333 ECC"
                            },
                            {
                               "model":"Super Talent 4GB DDR3 1333 ECC"
                            }
                         ],
                

                我希望它类似于......

                I would expect it to be something along the lines of...

                $json = json_decode($jsondata, true);
                
                foreach ($json as $item)
                {
                    foreach ($item['assets']->RAM as $asset)
                    {
                        echo $asset->model;
                    }
                

                推荐答案

                来自php官方文档:http://php.net/manual/fr/function.json-decode.php

                第二个 func arg 用于关联数组返回.如果您更喜欢在对象上操作关联数组,则可以使用它.

                The 2nd func arg is for assoc array return. You can use it if you prefer to manipulate assoc array over object.

                但你实际上在循环中混合了数组和对象.

                But you actually mix array and object in your loop.

                如果您将参数保持在 TRUE,请使用 $item['assets']['RAM']

                If you keep the arg at TRUE, please use $item['assets']['RAM']

                这篇关于用 PHP 解析 JSON 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 PHP glob 获取文件夹 - 深度无限 下一篇:在 foreach 中,isLastItem() 存在吗?

                相关文章

                最新文章

                    <bdo id='t1AKo'></bdo><ul id='t1AKo'></ul>
                1. <legend id='t1AKo'><style id='t1AKo'><dir id='t1AKo'><q id='t1AKo'></q></dir></style></legend>
                  1. <i id='t1AKo'><tr id='t1AKo'><dt id='t1AKo'><q id='t1AKo'><span id='t1AKo'><b id='t1AKo'><form id='t1AKo'><ins id='t1AKo'></ins><ul id='t1AKo'></ul><sub id='t1AKo'></sub></form><legend id='t1AKo'></legend><bdo id='t1AKo'><pre id='t1AKo'><center id='t1AKo'></center></pre></bdo></b><th id='t1AKo'></th></span></q></dt></tr></i><div id='t1AKo'><tfoot id='t1AKo'></tfoot><dl id='t1AKo'><fieldset id='t1AKo'></fieldset></dl></div>

                    <tfoot id='t1AKo'></tfoot>

                  2. <small id='t1AKo'></small><noframes id='t1AKo'>