任何人有问题从ColdFusion的serializeJSON方法到PHP的json_decode? [英] Anyone have issues going from ColdFusion's serializeJSON method to PHP's json_decode?

查看:165
本文介绍了任何人有问题从ColdFusion的serializeJSON方法到PHP的json_decode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Interwebs对此没有帮助。我们使用 serializeJSON 在ColdFusion中编码数据,并尝试使用 json_decode 在PHP中解码。大多数时候,这是工作正常,但在某些情况下, json_decode 返回 NULL 。我们已经找到了明显的罪魁祸首,但 serializeJSON 似乎正在按预期格式化事情。还有什么可能是问题?



更新:有几个人(明智地)要求我发布导致问题的输出。我会,但我们只是发现,结果集是我们所有的数据(2300+租赁属性总共565135个ASCII字符的列表信息)!这可能是一个问题,虽然我没有看到任何关于字符串的最大大小的PHP文档。那里的限制因素是什么? RAM?



UPDATE II:看起来问题是我们的一些用户已经复制和粘贴带有智能报价的Microsoft Word文本。那些讨厌的用户...

解决方案

你可以尝试在UTF-8操作并让PHP知道这个事实。 >

我有一个问题,PHP的 json_decode 无法解码UTF-8 JSON字符串(有一些怪异字符除了你有的卷曲引号外)。我的解决方案是提示PHP,我是在UTF-8模式下工作,通过在HTML页面中插入一个Content-Type元标签,正在提交到PHP。这样,提交的数据(即JSON字符串)的内容类型也将是UTF-8:

 < meta http-equiv =Content-Typecontent =text / html; charset = utf-8/> 

之后,PHP的 json_decode 正确解码字符串。


The Interwebs are no help on this one. We're encoding data in ColdFusion using serializeJSON and trying to decode it in PHP using json_decode. Most of the time, this is working fine, but in some cases, json_decode returns NULL. We've looked for the obvious culprits, but serializeJSON seems to be formatting things as expected. What else could be the problem?

UPDATE: A couple of people (wisely) asked me to post the output that is causing the problem. I would, except we just discovered that the result set is all of our data (listing information for 2300+ rental properties for a total of 565,135 ASCII characters)! That could be a problem, though I didn't see anything in the PHP docs about a max size for the string. What would be the limiting factor there? RAM?

UPDATE II: It looks like the problem was that a couple of our users had copied and pasted Microsoft Word text with "smart" quotes. Those pesky users...

解决方案

You could try operating in UTF-8 and also letting PHP know that fact.

I had an issue with PHP's json_decode not being able to decode a UTF-8 JSON string (with some "weird" characters other than the curly quotes that you have). My solution was to hint PHP that I was working in UTF-8 mode by inserting a Content-Type meta tag in the HTML page that was doing the submit to the PHP. That way the content type of the submitted data, which is the JSON string, would also be UTF-8:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

After that, PHP's json_decode was able to properly decode the string.

这篇关于任何人有问题从ColdFusion的serializeJSON方法到PHP的json_decode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆