从 SQL Server 中的 JSON 字符串中提取 GUID

问题描述

我需要从 sql Server 中的 json 字符串中提取一些 GUID。该字符串的示例如下所示:

operation2

我需要的 GUID 是在 'resourceWidget-[number]' 之后的那个。即使 json 字符串每次看起来都一样,我也会为此而挣扎,但还有进一步的挑战:

  1. resourceWidget 在字符串中的位置根据前端行为而变化
  2. 每个字符串中“resourceWidget-”变化之后的唯一编号
  3. 有时会在字符串中返回多个资源 GUID,例如

resourceWidget-1555338252504":"98714348-cf7d-4583-89d5-c7d61cafea72,87ea276b-5b7f-4b44-b05e-775e9fd2690c

如果有人能够提供帮助,将不胜感激。

解决方法

看起来像一个简单的 inputLat.textProperty().bindBidirectional(pm.latProperty(),new NumberStringConverter("#######.##")); 调用和一个 Juni 23,2021 1:29:17 PM com.sun.javafx.binding.BidirectionalBinding$StringConversionBidirectionalBinding changed WARNUNG: Exception while parsing String in bidirectional binding java.lang.RuntimeException: java.text.ParseException: Unparseable number: "-" Caused by: java.text.ParseException: Unparseable number: "-" at java.base/java.text.NumberFormat.parse(NumberFormat.java:434) at javafx.util.converter.NumberStringConverter.fromString(NumberStringConverter.java:94) ... 52 more 可以工作:

OPENJSON

如果 JSON 可以包含分隔字符串,请添加 WHERE

DECLARE @JSON nvarchar(MAX) = N'{
    "priorityArea": "a273b556-f0ab-4d7a-97ac-ddb7dab06130","priority": "Ensure best possible provision for pupils with specific behaviour issues","startDatePicker": "10/05/2019","deadlineDatePicker": "18/09/2019","userPicker": "48698,48693","actionWidget-1555338252504": "85e3ad8f-2586-4612-a9e7-e1c9d3f66181,6b66328f-c13f-4d8c-81ec-fccb8c1caa6e","resourceWidget-1557502650616": "98714348-cf7d-4583-89d5-c7d61cafea72","sdpGrade-1555338253145": "4"
}';

SELECT TRY_CONVERT(uniqueidentifier,[value]) AS resourceWidget
FROM OPENJSON(@JSON)
WHERE [key] LIKE N'resourceWidget-%';