将javascript对象转换为字符串的php代码
我有 php 文件,我试图从中运行 firefox 并获得 yslow 结果。但 yslow 结果以对象形式发送,例如 [object Object] 结果使用 post 方法发送。 如何在php代码中将其转换为字符串并显示到网页上???
I have php file from which i am trying to run firefox and getting yslow results. But yslow results are sent in object form some thing like [object Object]
results are sent using post method.
how can convert it into string in php code and display to web page???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你的问题有点含糊。听起来您正在尝试发布一个正在转换为字符串的 JavaScript 对象。
如果要将对象包含在 POST 数据中,则需要序列化该对象。
Your question is a bit ambigues. it sounds like you are trying to post a javascript object which is getting converted to a string.
You need to serialize the object if you want to include it in POST data.
如果您的对象被传递给 JSON.stringify,那么它应该作为字符串返回。
如果 b 本质上是您发送到服务器的内容,就像您提到的发布位置一样,如果您对 PHP 使用 json_decode (如建议的那样),它应该可以工作。
你应该得到
从那里你可以开始获取值。这是我根据您描述数据的方式进行测试的结果。
If your object gets passed to
JSON.stringify
then is should be returned as string.If b is essentially what you're sending to the server like you mentioned where it is being POSTed, if you use json_decode to your PHP (as suggested), it should work.
You should get
From there you can start getting values. This is from what I tested based on how you described your data.
我假设它以 JSON 形式发送,您可以使用 json_decode 函数 -
http://php.net/manual/en/function.json-decode.php
I'm assuming it's sent as JSON which you can use the json_decode function -
http://php.net/manual/en/function.json-decode.php
JavaScript 对象字符串和 JSON 之间的区别在于,对于 JSON,变量名 foo 用双引号括起来。 json_decode 不适用于 JavaScript 对象字符串。
The difference between JavaScript object string and JSON is that with JSON the variable name foo is enclosed in double quotes. json_decode doesn't work with JavaScript object strings.