解析字符串SQL Server,Ruby,Python?

发布于 2025-01-19 13:24:35 字数 316 浏览 0 评论 0原文

我正在尝试解析这种数据的刺痛...它是来自API获取的一个领域...

{"displayValue"=>"LNA1234", "isMulti"=>true, "textValue"=>"PNA64582", "type"=>"entity_link", "value"=>["srp_zfeedr88N"]}

看起来很熟悉。就像Ruby中的JSON HASH一样……

什么是解析此方法的最佳方法。我将数据放在SQL Server表中,因此更可取TSQL。但是,如果更好的话,我也会考虑Ruby或Python。

I'm trying to parse this sting of data...its an field coming from an API GET...

{"displayValue"=>"LNA1234", "isMulti"=>true, "textValue"=>"PNA64582", "type"=>"entity_link", "value"=>["srp_zfeedr88N"]}

It looks familiar. Like a JSON hash in ruby...

What would be the best method to parse this. I have the data in a SQL Server table so TSQL preferable. But I would also consider Ruby or Python if it was better..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌化 2025-01-26 13:24:35

您可以尝试将存储的API数据转换为JSON。

示例数据:

SELECT *
INTO Data
FROM (VALUES
   ('{"displayValue"=>"LNA1234", "isMulti"=>true, "textValue"=>"PNA64582", "type"=>"entity_link", "value"=>["srp_zfeedr88N"]}'),
   ('Invalid JSON data')
) v (ApiData)

语句:

SELECT t.ApiData, j.*
FROM (
   SELECT 
      ApiData,
      JsonData = CASE
         WHEN ISJSON(REPLACE(ApiData, '=>', ':')) = 1 THEN REPLACE(ApiData, '=>', ':')
         ELSE NULL
      END   
   FROM Data
) t  
OUTER APPLY OPENJSON(t.JsonData) j

结果:

apidata键值类型{“ displayValue” =>“ lna1234”,“ ismulti” => true,“ textValue” =>“ pna64582
”,“ pny64582”,“ type” => “ value” => [srp_zfeedr88n']}}displayValuelna12341
{“ displayValue” =>“ lna1234”,“ ismulti” => true,true,“ textValue,” textValue,“ textValue” => “ entity_link”,“ value” => [“ srp_zfeedr88n”]}ismultitrue3
{“ displayValue” =>“ lna1234”,“ ismulti” => trie,trie,true,trie,triev; “ =>” entity_link”,“ value” => [srp_zfeedr88n']}textValuepna645821
{“ displayValue” =>“ lna1234” “,” type“ =>” entity_link“,“ value” => [srp_zfeedr88n']}typeentity_link1
{“ displayValue” =>“ lna1234”,“ >“ pna64582”,“ type” =>“ entity_link”,“ value” => [srp_zfeedr88n'}value[srp_zfeedr88n']4
无效的JSON DATA

You may try to transform and parse the stored API data as JSON.

Sample data:

SELECT *
INTO Data
FROM (VALUES
   ('{"displayValue"=>"LNA1234", "isMulti"=>true, "textValue"=>"PNA64582", "type"=>"entity_link", "value"=>["srp_zfeedr88N"]}'),
   ('Invalid JSON data')
) v (ApiData)

Statement:

SELECT t.ApiData, j.*
FROM (
   SELECT 
      ApiData,
      JsonData = CASE
         WHEN ISJSON(REPLACE(ApiData, '=>', ':')) = 1 THEN REPLACE(ApiData, '=>', ':')
         ELSE NULL
      END   
   FROM Data
) t  
OUTER APPLY OPENJSON(t.JsonData) j

Result:

ApiDatakeyvaluetype
{"displayValue"=>"LNA1234", "isMulti"=>true, "textValue"=>"PNA64582", "type"=>"entity_link", "value"=>["srp_zfeedr88N"]}displayValueLNA12341
{"displayValue"=>"LNA1234", "isMulti"=>true, "textValue"=>"PNA64582", "type"=>"entity_link", "value"=>["srp_zfeedr88N"]}isMultitrue3
{"displayValue"=>"LNA1234", "isMulti"=>true, "textValue"=>"PNA64582", "type"=>"entity_link", "value"=>["srp_zfeedr88N"]}textValuePNA645821
{"displayValue"=>"LNA1234", "isMulti"=>true, "textValue"=>"PNA64582", "type"=>"entity_link", "value"=>["srp_zfeedr88N"]}typeentity_link1
{"displayValue"=>"LNA1234", "isMulti"=>true, "textValue"=>"PNA64582", "type"=>"entity_link", "value"=>["srp_zfeedr88N"]}value["srp_zfeedr88N"]4
Invalid JSON data
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文