Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This my text in database:

"推奨切削条件 "

in PHP, i using Json_encode: Result:

{"table1":[{"Item":{"original_text":"u63a8u5968u5207u524au6761u4ef6 "}}]};

In javascript :

var strData ='{"table1":[{"Item":{"original_text":"u63a8u5968u5207u524au6761u4ef6 "}}]}';//getData();
strData=strData.replace(/
/g, "\n").replace(/
/g, "\r").replace(/	/g, "\t");      
var jsonData = JSON.parse(strData)

Error:

Uncaught SyntaxError: Unexpected token  in JSON at position 56
    at JSON.parse (<anonymous>)

enter image description here How can parse JSon with special characters?

Thanks all.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
375 views
Welcome To Ask or Share your Answers For Others

1 Answer

i have to copy json to js

I have no idea why, but okay… You don't need to deal with it as JSON string inside Javascript at all then. JSON is a valid Javascript literal. So just paste your JSON into your Javascript without the quotes:

var data = {"table1":[{"Item":{"original_text":"u63a8u5968u5207u524au6761u4ef6 "}}]};

This is a perfectly valid Javascript object literal which requires no parsing.

If you need a valid Javascript string literal containing a JSON string, json_encode(json_encode(...)) it twice to get:

var strData = "{"table1":"\u63a8\u5968\u5207\u524a\u6761\u4ef6 \b"}";
console.log(JSON.parse(strData));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...