php 如何将json转换为字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3377736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:31:23  来源:igfitidea点击:

how to convert json to string

phpmysqljson

提问by user401000

how do i convert a json object to a string

我如何将 json 对象转换为字符串

i want to insert a json object to a mysql DB

我想将一个 json 对象插入到 mysql 数据库中

回答by VolkerK

You might be interested in json_encode().

您可能对json_encode()感兴趣。

On the other hand if you already got something json encoded then it already is a string and you can simply store it as-is in the database.

另一方面,如果你已经得到了一些 json 编码的东西,那么它已经是一个字符串,你可以简单地将它按原样存储在数据库中。

回答by Ramesh Seera

JSON itself is a string. People use json_encode() and json_decode() to convert objects/arrays of PHP to string and back to objects/arrays.

JSON 本身是一个字符串。人们使用 json_encode() 和 json_decode() 将 PHP 的对象/数组转换为字符串,然后再转换回对象/数组。