Php 这个json怎么会无效?
实际上,我对这个json是如何无效感到困惑。我有一个更大的json集合中的json片段:Php 这个json怎么会无效?,php,mysql,json,Php,Mysql,Json,实际上,我对这个json是如何无效感到困惑。我有一个更大的json集合中的json片段: ... "open_until":{ "date":"2015-10-16 00:00:00", "timezone_type":3, "timezone":"America\/Edmonton" },
...
"open_until":{
"date":"2015-10-16 00:00:00",
"timezone_type":3,
"timezone":"America\/Edmonton"
},
"ffba_access_code":"1234",
"overview_content":"
Elevator Pitch<\/h4>\r\n
Fedilus Funds gives investors the ability to participate in the growth of the United States un-banked sector by deploying 'automated commerce machines' in high traffic areas. This is a blended investment that distributes monthly principal and interest back to the investor and once the term has ended, a percentage of revenue is distributed continuously. You are purchasing a portfolio of advanced ATM's that offer a wide range of financial services coupled with a strong management team.<\/p>\r\n\r\n
This is a USD investment with monthly distributions remitted in USD.<\/p>",
.....
当我将其通过json格式化程序时,我被告知:
"
Elevator Pitch<\/h4>\r\n
Fedilus Funds gives investors the ability to participate in the growth of the United States un-banked sector by deploying 'automated commerce machines' in high traffic areas. This is a blended investment that distributes monthly principal and interest back to the investor and once the term has ended, a percentage of revenue is distributed continuously. You are purchasing a portfolio of advanced ATM's that offer a wide range of financial services coupled with a strong management team.<\/p>\r\n\r\n
This is a USD investment with monthly distributions remitted in USD.<\/p>"
这是无效的令人讨厌的佩斯吗
我可以从php中的数据库中找到这个。当我将此特定数据库字段拉出以使其符合要求时,是否应该对其执行某些操作?出于此原因,属性值或属性中不能有换行符 这个例子很好:
...
"open_until": {
"date": "2015-10-16 00:00:00",
"timezone_type": 3,
"timezone": "America/Edmonton"
},
"ffba_access_code": "1234",
"overview_content": "Elevator Pitch</h4>\r\n Fedilus Funds gives investors the ability to participate in the growth of the United States un-banked sector by deploying 'automated commerce machines' in high traffic areas. This is a blended investment that distributes monthly principal and interest back to the investor and once the term has ended, a percentage of revenue is distributed continuously. You are purchasing a portfolio of advanced ATM's that offer a wide range of financial services coupled with a strong management team.</p>\r\n\r\n This is a USD investment with monthly distributions remitted in USD.</p>"
...
JSON不允许真正的换行符。您需要将所有换行符替换为\n。正如一些人指出的那样,将数据库中的内容包装起来是解决问题的诀窍。关于需要转义的换行符,上面的答案是正确的。查看php的内置json_encode函数
此外,这个答案还有一些关于换行符和转义反斜杠的有用信息:您是否尝试在概述内容文本中使用htmlspecialchars?如果我没记错,换行符无效…@Andre So sicne我从数据库中提取了数据,如何使其有效?通过。让我反过来问这个问题:你为什么要手动编码?@Andre:你没记错:换行符是一个控制字符。@VolkerK嗯,我对数据库中的内容进行了编码你是说问题中显示的错误json已经存在于数据库中;你是从text/varchar字段中提取的吗?在这种情况下:是什么将无效的enocded not json放在数据库中?无论如何,不会对换行符/换行符执行任何操作。此函数处理的字符为&、,