Php 从mysql数据库查询并解码json

Php 从mysql数据库查询并解码json,php,mysql,json,Php,Mysql,Json,我的mysql数据库中有这个JSON编码的代码: {"Suggestion":{"Title":"Casinos","Text":"maybe it will be good if its there casinos "},"ID":6,"VoteNo":[],"Status":"Voting","Player":{"SteamID":"STEAM_0:1:36988062","Name":"Pepi"},"Approved":{"Name":"Nido Johnson","Is":true,"

我的mysql数据库中有这个JSON编码的代码:

{"Suggestion":{"Title":"Casinos","Text":"maybe it will be good if its there casinos "},"ID":6,"VoteNo":[],"Status":"Voting","Player":{"SteamID":"STEAM_0:1:36988062","Name":"Pepi"},"Approved":{"Name":"Nido Johnson","Is":true,"SteamID":"STEAM_0:0:47457253"},"VoteYes":{"1":"STEAM_0:0:56939043","2":"STEAM_0:0:55948188","3":"STEAM_0:1:25856984","4":"STEAM_0:1:40894071"}}

我想查询并解码它,以便在我的网站上回复它。

您必须使用php json_解码函数来解码json编码的数据。 基本上,json_decode函数将json数据转换为PHP数组

语法:json_解码数据、dataTypeBoolean、深度、选项

data:-要在PHP中解码的json数据

dataTypeBooleanOptional:-布尔值,如果设置为true,则使函数返回PHP关联数组;如果忽略此参数或将其设置为false,则使函数返回PHP stdClass对象。这两种数据类型都可以像数组一样访问,并使用基于数组的PHP循环进行解析

深度:-可选递归限制。使用整数作为此参数的值

选项:-可选JSON_BIGINT_作为字符串参数

现在来看看你的代码

将有效的json数据分配给单引号内的变量$json_字符串,如下所示 json字符串已经有双引号

    $json_string = '{"Suggestion":{"Title":"Casinos","Text":"maybe it will be good if its there casinos "},"ID":6,"VoteNo":[],"Status":"Voting","Player":{"SteamID":"STEAM_0:1:36988062","Name":"Pepi"},"Approved":{"Name":"Nido Johnson","Is":true,"SteamID":"STEAM_0:0:47457253"},"VoteYes":{"1":"STEAM_0:0:56939043","2":"STEAM_0:0:55948188","3":"STEAM_0:1:25856984","4":"STEAM_0:1:40894071"}}';
// here i am decoding a json string by using a php 'json_decode' function, as mentioned above & passing a true parameter to get a PHP associative array otherwise it will bydefault return a PHP std class objecy array.

    / just can check here your encoded array data.
// echo '<pre>';
// print_r($json_decoded_data);

// loop to extract data from an array
foreach ($json_decoded_data as $key => $value) {
    echo "$key <br/>";
    foreach($value as $k=>$data)
    {
        echo "$k | $data <br/>";
    }

}