wordpress json_decode 不起作用,我正在尝试从 wp_option 表中获取值 [英] wordpress json_decode is not working, I am trying to get value form wp_option table

查看:37
本文介绍了wordpress json_decode 不起作用,我正在尝试从 wp_option 表中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用此代码解码 JSON 时,输出为

When I am trying to decode JSON with this code the output is

ArrayArray ( [0] => )

我不知道为什么 WordPress 不支持这个

I do not know why WordPress doesn't support this

 <?php
    global $wpdb;
    $mylink = $wpdb->get_results( "SELECT option_value FROM wp_options WHERE option_id=62167", ARRAY_N );
    $raw = stripslashes_deep($mylink);
            $data = array();
            foreach ($raw as $json) {
                        echo $json;

                $item = @json_decode($json, true);

                $data[] = $item;

                            print_r($data);

            }
    ?>

推荐答案

您好,您的查询从数据库中获取数据时,您需要先对数据进行反序列化,这是序列化的数据,当我们从数据库中获取它时,我们需要将其取消序列化.

Hello you need to unserealize the data first when your query get data from database, That is serealized data and when we get it from db we need to unserealize it.

 global $wpdb;
    $mylink = $wpdb->get_results("SELECT option_value FROM wp_options WHERE option_id=1223",ARRAY_A);

   $raw = stripslashes_deep($mylink);
  $data = $raw[0]['option_value'];
  $datas = unserialize($data);
  foreach ($datas as $key => $value) {
    print_r($value);
  }

这篇关于wordpress json_decode 不起作用,我正在尝试从 wp_option 表中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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