Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert json string to php variable

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to convert json string into php variable", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "how to convert json string into php variable" this article bar.

In php, you can convert a json string to a PHP variable using the json_decode() function; this function can be used to decode a JSON string, it takes a JSON-encoded string and converts it to a PHP variable, syntax "json_decode($json)".

Operating environment of this tutorial: Windows 7 system, PHP7.1 version, DELL G3 computer

In php, you can use the json_decode() function to convert a json string to a PHP variable.

The json_decode() function decodes strings in JSON format.

Grammar:

json_decode( string $json, bool $assoc = false, int $depth = 512, int $options = 0)

The json_decode() function takes a JSON-encoded string and converts it to a PHP variable.

Parameters:

json: Used to contain the JSON string to be decoded. It applies only to UTF-8 encoded strings.

assoc: This is a Boolean variable and can be omitted. The default value is false and returns the value of the object type; if true, the returned object is converted to an associative array type.

depth: Used to indicate the user-specified recursive depth, can be omitted.

options: binary mask, can be omitted, can include: JSON_OBJECT_AS_ARRAY, JSON_BIGINT_AS_STRING, JSON_THROW_ON_ERROR

return value

Returns data encoded in json with the appropriate PHP type. Values true, false, and null return true, false, and null accordingly. If json cannot be decoded, or if the encoded data depth exceeds the recursion limit, null will be returned.

Examples:

The above routine outputs:

The above is "how to convert json string to php variable" all the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 288

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report