【问题标题】:Is it possible to print the value of Key from the (key-value)pair of json object in laravel是否可以从 laravel 中 json 对象的(键值)对打印 Key 的值
【发布时间】:2018-10-03 09:36:03
【问题描述】:

如何从 laravel 中的 json 对象打印“key”值。

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"
  }
},

如何从上述数据中显示“in”?

【问题讨论】:

    标签: json laravel laravel-5 laravel-5.2 laravel-5.1


    【解决方案1】:

    JSON 放入一个变量中。前任。 $jsonVariable.

    json_decode($jsonVariable)->pricing->in
    

    【讨论】:

      【解决方案2】:

      首先,我认为你的 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;
          }
      

      【讨论】:

        猜你喜欢
        • 2018-10-06
        • 2016-05-13
        • 2013-05-04
        • 1970-01-01
        • 2020-04-08
        • 2013-10-20
        • 1970-01-01
        • 1970-01-01
        • 2017-04-30
        相关资源
        最近更新 更多