sql - Japanese Characters are not recognized when using Invoke-SqlCmd -Query
问题描述
I'm inserting data from a json file to an SQL server table using Invoke-SqlCmd and using a stored procedure as following:
Invoke-SqlCmd -ServerInstance $servername -Database $database -Query "EXEC dbo.InsertDataFromJson @JSON='$json'
The json is obtained by getting it's raw content:
$json = Get-Content -Path "path\to.json" -Raw
$json # Content:
'{"Id": "2fe2353a-ddd7-479a-aa1a-9c2860680477",
"RecordType": 20,
"CreationTime": "2021-02-14T08:32:23Z",
"Operation": "ViewDashboard",
"UserKey": "10099",
"Workload": "PowerBI",
"UserId": "102273335@gmail.com",
"ItemName": "テスト",
"WorkSpaceName": "My Workspace",
"DashboardName": "テスト",
"ObjectId": "テスト" }'
All the column with strings, emails and japanese characters are NVARCHAR(MAX).
The problem is my json contains Japanese characters and they appear as ???? in the table.
When I try to insert a sample using SSMS directly it works fine.
Do you have any idea how to fix this ?
Thank you
解决方案
尝试将 -Encoding 标志设置为 Utf8。
{"test":"みんな"}
Get-Content -Path ".\test.json" -Encoding Utf8
推荐阅读
- delphi - 将 TPoupMenu 分配给 TAdvColumnGrid 中的 Inplace 编辑器
- r - 计算测量值之间的增量,同时在 R 中的行间保留相同的单位
- php - post_class 字面打印
- excel-formula - SUMPRODUCT 效果不佳
- python - Python Selenium Webdriver - 删除 Facebook 帖子时无法找到元素
- android - Android - 约束布局不会尊重边距?
- swift - Swift - 通过代码链接 UIViewController
- cryptography - JWT 对普通消息 + HMAC 的好处?
- django - 同一搜索页面中的 Django 分页
- visual-studio-code - 执行建议的操作 VS 代码