2015-09-30 2 views
-2

Я действительно смущен здесь, как этот 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>" 

это «нарушители» peice то будет «недействителен "

Я использую это право из базы данных в php. Есть ли что-то, что я должен сделать для этого конкретного поля базы данных, когда я вытаскиваю его, чтобы он соблюдался?

+0

сделал вы пытались использовать 'htmlspecialchars' для overview_content текста? –

+3

Если я правильно помню, разрывы строк недействительны ... – Andre

+0

@Andre So sicne Я вытащил данные из базы данных, как я могу сделать это действительным? – TheWebs

ответ

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

JSON не позволяет реальные разрывы строк. Вам нужно заменить все разрывы строк на \ n.

-3

Как некоторые отметили, что содержимое, которое выходит из базы данных в htmlspecialchars, сделало трюк для устранения проблемы.

+0

@VolkerK Ум я сделал это по содержимому, поступающему из базы данных – TheWebs

+1

Вы имеете в виду неисправный json, поскольку показ в вопросе уже находится в базе данных; вы извлекаете это из поля text/varchar? В этом случае: что помещает неверно enocded (not-) json в базу данных? Во всяком случае, [htmlspecialchars()] (http://docs.php.net/htmlspecialchars) ничего не делает для символов linebreak/feed. Символами, обрабатываемыми этой функцией, являются '&', '' ',' '', '<' and '>' – VolkerK

0

Ответы, приведенные выше, являются правильными в отношении разрывов строк, которые необходимо избегать. Проверьте встроенную функцию php json_encode().

Кроме того, этот ответ имеет некоторые полезные данные о разрывы строк и избежать обратной косой черты: Multiline strings in JSON

Смежные вопросы