System.FormatException: 24141: 输入的第 47 位需要一个数字。输入有 )

System.FormatException: 24141: A number is expected at position 47 of the input. The input has )

我在 sqlserverdb 中有一个 table,其中包含列名称 EntityType,EntityJson.In EntityJson 列包含以下 json 值,

{"EntityId":{"Type":"String","Value":"bf58bbc6-0a5a-b9e0-4fb6-5e55604a1b68"},"Name":{"Type":"string","Value":"GasAssets"},"TenantName":{"Type":"string","Value":"v2rdemo"},"TenantId":{"Type":"string","Value":"c091e548-b45a-49b4-b8ec-2cb5e27c7af6"},"EntityType":{"Type":"string","Value":"EntityAssets"},"CreatedBy":{"Type":"string","Value":""},"ModifiedBy":{"Type":"string","Value":""},"Created":{"Type":"string","Value":""},"Modified":{"Type":"string","Value":""},"Parent":{"Type":"string","Value":""},"LastChat":{"Type":"string","Value":""},"Latitude":{"Type":"string","Value":-33.3479019999504},"Longitude":{"Type":"string","Value":6.203906305532271}}

并且 EntityType 列值为 "EntityAssets"。

我在 GeoServer 上编写了以下查询

SELECT
  geometry::STGeomFromText('POINT(' + CAST(JSON_VALUE(EntityJson, '$.Latitude.Value') As CHAR(20)) + ' ' + CAST(JSON_VALUE(EntityJson, '$.Longitude.Value') AS CHAR(20)) + ')', 4326) as geometria 
FROM
   dbo.Entities 
where
   EntityType = 'EntityAssets'

在单击 openlayer 预览图层时出现相同的异常。

但是在 Microsoft Sql Server Mgmt Studio 运行 它与 where 子句一起工作正常,如果我删除 where 子句并再次执行不带 where 子句的查询在 Sql 服务器上得到相同的异常管理工作室。

A number is expected at position 47 of the input. The input has ).

如果没有看到您的数据,很难确定,但错误听起来像是您有一行 Latitude.ValueLongitude.Value 没有或为空。 运行 这个查询你会得到一个非常相似的错误:

SELECT
  geometry::STGeomFromText('POINT(' + '' + ' ' + '' + ')', 4326) as geometria 
FROM
   dbo.Entities

这会模拟您的两个 CAST 返回空字符串。

另见 this old question on MSDN