问题
I am getting data from remote sql server like this .
"USER_NAME" = "???? ??????";
I have to get value of username in arabic language but I am getting ??????. I have navchar type of text filed at database. I am using these lines of code:-
NSString *output = [[feed objectForKey:@"USER_NAME"] stringByReplacingPercentEscapesUsingEncoding:NSUnicodeStringEncoding];
NSLog(@"%@",output);
So How can I fixed this?
回答1:
There can be two possible reasons for sql server to show some unicode data like ????????
Reason 1.
when unicode data wan inserted or updated to that column the user didnt prefix the string withN
.Reason 2.
The Column itself isnt NVARCHAR means it doesnt allow storing unicode characters to be stored.
Example
DECLARE @TABLE TABLE
(Column1 VARCHAR(100), --<-- VARCHAR DataType
Column2 NVARCHAR(100), --<-- NVARCHAR DataType
Column3 NVARCHAR(100)COLLATE Arabic_CI_AS --<-- NVARCHAR DataType with specific
) -- arabic collation
INSERT INTO @TABLE VALUES
('هذا هو العربي','هذا هو العربي', 'هذا هو العربي'), -- Data with out N Prefix
(N'هذا هو العربي',N'هذا هو العربي', N'هذا هو العربي') -- Data with N Prefix
SELECT * FROM @TABLE
Result
╔═══════════════╦═══════════════╦═══════════════╗
║ Column1 ║ Column2 ║ Column3 ║
╠═══════════════╬═══════════════╬═══════════════╣
║ ??? ?? ?????? ║ ??? ?? ?????? ║ ??? ?? ?????? ║
║ ??? ?? ?????? ║ هذا هو العربي ║ هذا هو العربي ║
╚═══════════════╩═══════════════╩═══════════════╝
Only data Where Column allows unicode characters to be stored and when I used N prefix will have data stored in the rest are only showing ???????.
In your case you have simply lost the data you cannot possibly convert it back to unicode / Arabic characters . Ouch :S
来源:https://stackoverflow.com/questions/21203330/convert-in-to-arabic-language