2012-09-02 47 views
4

我的表中有一列JSON字符串,我正在使用SQL Server 2008. 任何有关如何解析JSON字符串并提取特定值的想法?解析SQL中的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}]} 

我需要提取 “名” 的价值,任何帮助吗?

+0

几乎DUP的[解析JSON在TSQL](http://stackoverflow.com/q/2867501/1178314),它与一个参数要求作为源而不是列,但有很好的答案,现在在SQL Server 2016中提到了本机JSON支持。 –

回答

8

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

但是,你总是可以使用别人的JSON parsing library

2

对于解析JSON,你可以在C#或VB.NET中编写一个简单的CLR Function