I have a french character (à) in my JSON String 'd'instruments cordes à'. But the (à) character shows JSON error when displaying. I want to display the exact character in my UI.
Asked
Active
Viewed 303 times
-1
-
2please show us some code – Aᴍɪʀ Jan 27 '21 at 06:08
-
How do you “display” the à? – MoPaMo Jan 27 '21 at 06:09
-
à is considered a special character in JSON. – ReaL_HyDRA Jan 27 '21 at 06:12
-
From my experience, you can just use special characters, in JSON as long as they don’t include a \ or " – MoPaMo Jan 27 '21 at 06:15
-
Can you include your actual JSON string? There should be no issue with using that character. Are you sure the issue isn't the single quote? – JoshG Jan 27 '21 at 06:20
-
`["634149","d'instruments cordes u00E0","America"] ` . The Actual string stored in database is `'d'instruments cordes à'` – ReaL_HyDRA Jan 27 '21 at 06:44
2 Answers
0
You really should provide more details. As of now, it's unclear whether you are generating or parsing your JSON in the database.
Regardless, below is a short sample demonstrating that "à" is not a special character in any way. Compare the code below with yours, and especially pay attention to the difference between varchar
and nvarchar
. I think that's where your problem is.
declare @j nvarchar(max);
declare @t table (
Id int,
Value nvarchar(100),
Country varchar(50)
);
insert into @t (Id, Value, Country)
values
(634149, N'd''instruments cordes à', 'America');
-- Shows data in the table
select * from @t;
set @j = (
select *
from @t t
for json path, without_array_wrapper
);
-- Shows generated JSON
select @j as [GeneratedJSON];
-- Shows JSON query output
select *
from openjson(@j) with (
Id int '$.Id',
Value nvarchar(100) '$.Value',
Country varchar(50) '$.Country'
) j;

Roger Wolf
- 7,307
- 2
- 24
- 33
0
Make sure your page contains the following meta tag to support international characters.
<meta charset="utf-8" />

david-giorgi
- 145
- 2
- 10