0

I'm having trouble getting my head around storing some translations in our product database (MySQL) and retrieving them.

Our admin page takes simplified Chinese text and stores it in a MySQL Database for later retrieval.

My form for storing the Chinese character translations into the MySQL table stores the Chinese character string like this...

ç¡®ä¿ä¹˜å®¢æ•°é‡ä¸ä¼šå¤šäºŽ14人+ å¯å‰å¾€å¤–å ¡ç¤ = 乘åKianaå·çš„全新体验
Kianaå·ä¸Šå°†ä¼šå¸¦ä½ ä»¬æ¸¸è§ˆ74个壮观的圣çµç¾¤å²›ï¼Œæ›´å¯å‰å¾€å¤§å ¡ç¤å¤–围进行深潜。船上设有空调ã€å¤§åž‹ä¼šå®¢å®¤åŠèˆ’é€‚çš„èˆ¹èˆ±ç¡æˆ¿(包括两张标准å•人床的ç§äººæˆ¿)ã€‚èˆ¹ä¸Šçš„å®½é˜”ç”²æ¿æä¾›å¤§é‡ç©ºé—´ï¼Œè®©ä¹˜å®¢å¯ç©¿ä¸Šæµ®æ½œæˆ–深潜的潜水é…备。å†è€…,船上åªé™æœ€å¤šç››è½½14ä½ä¹˜å®¢ï¼Œæ‰€ä»¥ä½ ä»¬å¯ä»¥å°½æƒ…在甲æ¿ä¸Šäº«å—日光浴和欣èµç¾Žä¸½çš„风景。

The getJSON throws an error when trying to retrieve this string (Although it does the English character set just fine). It sends a statusText message of "parsererror".

However, studying the error produced shows the text (responseText) was correctly retrieved as...

{"LanguageID":"91","Field":"briefdesc","Text":"确保乘客数量不会多于14人+ 可前往外堡礁 =
乘坐Kiana号的全新体验
Kiana号上将会带你们游览74个壮观的圣灵群岛,更可前往大堡礁外围进行深潜。船上设有空调、大型会客室及舒适的船舱睡房(包括两张标准单人床的私人房)。船上的宽阔甲板提供大量空间,让乘客可穿上浮潜或深潜的潜水配备。再者,船上只限最多盛载14位乘客,所以你们可以尽情在甲板上享受日光浴和欣赏美丽的风景。"}

Running the Json through JSONLint produces this error..

Parse error on line 4:
...fdesc",    "Text": "确保乘客数量不会多于14人+ 可前往外
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

Ultimately JQuery is failing to parse this JSON I believe and it seems to be related to the fact the characters are simplified Chinese. Can anyone give me any clues how to get past the JSON Parse error ?

Cheers

Jonathan Lonowski
  • 117,332
  • 31
  • 195
  • 197
Craig
  • 385
  • 4
  • 16
  • 3
    I suggest you have a read of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Phil Jul 07 '14 at 04:19
  • JSON strings can't include literal newlines as your snippet shows. They should be represented with escape sequences, `\n` or `\r\n`. – Jonathan Lonowski Jul 07 '14 at 04:25
  • Thanks Jonathon, I have removed the literal new lines, but that hasn't solved the problem. – Craig Jul 07 '14 at 04:39
  • Thanks Phil. Answers like 'read this to learn PHP' or 'read this to learn JQuery' are not that helpful unless the reference specifically answers the question. – Craig Jul 07 '14 at 04:40
  • @Craig Did you actually read the top answer on that page? If that doesn't solve your question, I suggest you modify your question with what you tried. You've also neglected to add how your JSON is constructed from the MySQL data. – Phil Jul 07 '14 at 05:40

0 Answers0