这个json怎么样无效?

时间:2015-09-30 20:02:55

标签: php mysql json

我真的很困惑这个json是如何无效的。我有一张来自更大的json集的json:

               ...
               "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>"

是&#34;犯罪&#34; peice thats&#34;无效&#34;

我在php中的数据库中就是这样。当我将它拉出来使其符合时,我应该对这个特定的数据库字段做些什么吗?

4 个答案:

答案 0 :(得分:1)

您不能在属性值(或属性)中使用换行符。

这个例子很好看:

...
"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>"
...

答案 1 :(得分:1)

JSON不允许真正的换行符。您需要将所有换行符替换为\ n。

答案 2 :(得分:0)

上面的答案是关于需要转义的换行符。查看php的内置json_encode()功能。

此外,这个答案有一些关于换行符和转义反斜杠的有用信息:Multiline strings in JSON

答案 3 :(得分:-3)

正如一些人所指出的那样,在htmlspecialchars中包装来自数据库的内容,解决了这个问题。