有个网站经常换域名,山大优秀网站建设2018年度,中国制造网的网络营销方式,福州网站建设托管json_decode() 函数的第二个参数 $associative 是一个布尔值#xff0c;用于控制 JSON 对象在 PHP 中的解码方式。当将其设置为 true 时#xff0c;JSON 对象将被解码为关联数组#xff1b;当设置为 false 时#xff0c;JSON 对象将被解码为 stdClass 对象。默认值为 false…json_decode() 函数的第二个参数 $associative 是一个布尔值用于控制 JSON 对象在 PHP 中的解码方式。当将其设置为 true 时JSON 对象将被解码为关联数组当设置为 false 时JSON 对象将被解码为 stdClass 对象。默认值为 false。
语法
function json_decode ($json, $associative false, $depth 512, $flags 0) {}
以下是 json_decode() 函数的两种解码方式的示例
当 $associative 设置为 true 时JSON 对象将被解码为关联数组 ?php
$json {name: John, age: 30, city: New York};$decoded json_decode($json, true);print_r($decoded); // 输出Array ( [name] John [age] 30 [city] New York )
? 当 $associative 设置为 false 时默认值JSON 对象将被解码为 stdClass 对象 ?php
$json {name: John, age: 30, city: New York};$decoded json_decode($json);print_r($decoded); // 输出stdClass Object ( [name] John [age] 30 [city] New York )
? 在这两个示例中我们使用 json_decode() 函数解码 JSON 字符串。
第一个示例中我们将 $associative 参数设置为 true以便将 JSON 对象解码为关联数组。
第二个示例中我们将 $associative 参数设置为默认值 false以便将 JSON 对象解码为 stdClass 对象。