简体   繁体   English

是否有可能从Laravel中的json对象的(key-value)对打印Key的值

[英]Is it possible to print the value of Key from the (key-value)pair of json object in laravel

How to print the 'key' value from the json object in laravel. 如何从Laravel中的json对象打印'key'值。

The json array: json数组:

 "pricing": {
"in": {
  "categories": [
    "ccTLD",
    "Geography"
  ],
  "addons": {
    "dns": true,
    "email": true,
    "idprotect": true
  },
  "group": "",
  "register": {
    "1": "704.39"
  },
  "transfer": {
    "1": "704.39"
  },
  "renew": {
    "1": "704.39"
  }
},

How to display "in" from the above data? 如何显示以上数据中的“输入”?

Put JSON in a variable. JSON放入变量中。 Ex. 例如 $jsonVariable . $jsonVariable

json_decode($jsonVariable)->pricing->in

First of all i think there is some mistake in your json here is my funtion with two ways of achiving the same thing 首先,我认为您的json中有一些错误,这是我通过两种方法实现同一件事的功能

public function demo()
    {
        $json_array = '
        {
                "pricing": {

                        "in": {
                        "categories": [
                                "ccTLD",
                                "Geography"
                            ],
                        "addons": {
                                "dns": true,
                                "email": true,
                                "idprotect": true
                            },
                            "group": "",
                            "register": {
                                "1": "704.39"
                            },
                            "transfer": {
                                "1": "704.39"
                            },
                            "renew": {
                                "1": "704.39"
                            }
                        }

                    }
             }
         ';
        echo "<pre>";
       print_r(json_decode($json_array)->pricing->in);
       $asso_array = json_decode($json_array, true);
        print_r($asso_array["pricing"]["in"]);
       exit;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM