2016-02-25 33 views
1

你好我想創建一個JSON對象,但它顯示的錯誤無效字符發現這是我的JSON。創建JSON顯示錯誤無效字符發現

{ 
    "title":"Biology", 
    "content":"Egg period: 4 -6 days \n 
      Eggs laid in cracks and crevices of the loose bark on the trunk \n 
      Eggs: ovoid or elliptical and dirty white in colour \n 
      Adult :Reddish brown in colour", 
    "isSubtitle":"N" 
    } 

請幫助解決這個問題,並解釋無效字符的情況下,使JSON將有所幫助。

+0

你有沒有嘗試谷歌搜索「JSON驗證」或「JSON棉絨」,而不是?我們不是一個社區驅動的JSON驗證。 – PeeHaa

+0

@PeeHaa:使用jsonformatter vaildate我的JSON其示出了輸出作爲無效JSON(RFC 4627),錯誤:無效字符實測值[代碼18,結構式8] –

回答

2

JSON字符串中的換行符必須轉義爲\n。 JSON可以採取任何Unicode的字符,除非 - 「 - 或 - 或控制字符您的JSON應該是這樣的:

{ 
    "title": "Biology", 
    "content": "Egg period: 4 -6 days \n Eggs laid in cracks and crevices of the loose bark on the trunk \n Eggs: ovoid or elliptical and dirty white in colour \n Adult :Reddish brown in colour", 
    "isSubtitle": "N" 
} 

嘗試與jsonlint.com驗證對未來

2

此。 ,是無效的JSON格式,內容應該不會有換行符,所以你應該despecialize它是\\n 所以有效的格式爲:

{ 
    "title": "Biology", 
    "content": "Egg period: 4 -6 days \\n Eggs laid in cracks and crevices of the loose bark on the trunk \\n Eggs: ovoid or elliptical and dirty white in colour \\n Adult: Reddish brown in colour ", 
    "isSubtitle": "N" 
} 
相關問題