【问题标题】:Parse JSON string in sql在 sql 中解析 JSON 字符串
【发布时间】:2017-01-22 22:45:20
【问题描述】:

我的表中有一列 JSON 字符串,我使用的是 SQL Server 2008。 关于如何解析 JSON 字符串并提取特定值的任何想法?

这是我的 JSON 字符串:

{"id":1234,"name":"Lasagne al frono","description":"Placerat nisi turpis, dictumst nasceture ete etiam mus nec cum platea tempori zillest. Nisi niglue, augue adipiscing ete dignissim sed mauris augue, eros!","image":"images/EmptyProduct.jpg","cartImage":"images/ArabianCoffee.jpg","basePrice":54.99,"priceAttribute":"itemPrice","attributes":[{"type":"Addons","label":"Side","attributeName":"Side","display":"Small","lookupId":8},{"type":"Addons","label":"Drink","attributeName":"drink","display":"Small","lookupId":5},{"label":"add note","type":"Text","attributeName":"notes","display":"Wide","lookupId":null}]}

我需要提取“name”的值,有什么帮助吗?

【问题讨论】:

  • 几乎是 Parse JSON in TSQL 的重复,它使用参数作为源而不是列来询问,但有很好的答案,现在提到 SQL Server 2016 中的本机 JSON 支持。

标签: sql sql-server json sql-server-2008


【解决方案1】:

由于 sql server 没有内置 JSON 支持,所以需要手动解析,会比较复杂。

但是,您始终可以使用其他人的 JSON parsing library

【讨论】:

    【解决方案2】:

    为了解析 JSON,您可以用 C# 或 VB.NET 编写一个简单的CLR Function

    【讨论】:

      【解决方案3】:

      现在您可以使用 MS SQL Server 2016

      https://msdn.microsoft.com/en-us/library/dn921897.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-18
        • 2012-08-06
        • 2011-07-21
        • 2019-05-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多