【问题标题】:Issues retrieving special characters from OPENJSON SQL Server从 OPENJSON SQL Server 检索特殊字符的问题
【发布时间】:2019-07-11 00:49:33
【问题描述】:

我正在解析 JSON 文件中的数据,当我最终加载到我的表中时遇到问题,其中包含特殊字符(例如 ñ)的数据显示为 ñ。

代码在 NVARCHAR 中,我不确定为什么它没有正确拉动

INSERT INTO @recordsInfo
    (
        messageId,
        messageType,
        messageVariation,
        windowEnvelope,
        recipientFirstName,
        recipientLastName,
        recipientAddressLine1,
        recipientAddressLine2,
        recipientCity,
        recipientState,
        recipientZip,
        recipientZipSuffix
    )
    SELECT messageId,
           messageType,
           messageVariation,
           windowEnvelope,
           recipientFirstName,
           recipientLastName,
           recipientAddressLine1,
           recipientAddressLine2,
           recipientCity,
           recipientState,
           recipientZip,
           recipientZipSuffix
    FROM
        OPENJSON(@ValueR)
        WITH
        (
            messageId NVARCHAR(100),
            messageType NVARCHAR(100) '$.messageDetails.messageType',
            messageVariation NVARCHAR(100) '$.messageDetails.messageVariation',
            windowEnvelope NVARCHAR(100) '$.messageDetails.windowEnvelope',
            recipientFirstName NVARCHAR(100) '$."shippingDetails"."recipientFirstName"',
            recipientLastName NVARCHAR(100) '$."shippingDetails"."recipientLastName"',
            recipientAddressLine1 NVARCHAR(1000) '$.shippingDetails.recipientAddressLine1',
            recipientAddressLine2 NVARCHAR(100) '$.shippingDetails.recipientAddressLine2',
            recipientCity NVARCHAR(100) '$.shippingDetails.recipientCity',
            recipientState NVARCHAR(100) '$.shippingDetails.recipientState',
            recipientZip NVARCHAR(100) '$.shippingDetails.recipientZip',
            recipientZipSuffix NVARCHAR(100) '$.shippingDetails.recipientZipSuffix'
        );

DECLARE @recordsInfo TABLE
(
    RecID INT IDENTITY(1, 1),
    messageId NVARCHAR(100),
    messageType NVARCHAR(100),
    messageVariation NVARCHAR(100),
    windowEnvelope NVARCHAR(100),
    recipientFirstName NVARCHAR(100),
    recipientLastName NVARCHAR(100),
    recipientAddressLine1 NVARCHAR(1000),
    recipientAddressLine2 NVARCHAR(100),
    recipientCity NVARCHAR(100),
    recipientState NVARCHAR(100),
    recipientZip NVARCHAR(100),
    recipientZipSuffix NVARCHAR(100)
);

RecipientFirstName 是我正在查看的主要名称

【问题讨论】:

  • 表也是NVARCHAR吗?
  • @JacobH 是的,我相信是的
  • 您能否提供分配给“@ValueR”的内容?

标签: sql json sql-server


【解决方案1】:

JSON 通常是 UTF-8。 SQL Server 仅在 2019 版本中支持 UTF-8,因此在此之前,您必须手动完成。

Convert text value in SQL Server from UTF8 to ISO 8859-1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 1970-01-01
    • 2021-09-30
    相关资源
    最近更新 更多