通过字符串化JSON数组属性中包含的值过滤图层 [英] Filter a Layer By a Value Contained in a Stringified JSON Array Property
问题描述
我们的一个Mapbox图块集中的一个表具有ID的字符串化JSON数组属性:
One of the tables in one of our Mapbox tilesets has a stringified JSON array property of ids:
"string_ids":"[\"a\",\"b\"]"
I would like to filter features using this property, but can't seem to find a way to do it in the Predicates and Expressions documentation. So, for instance, I'd like to filter features so only those that have a "string_id" of "a" display.
我相信,这将有助于解决我的问题(准备就绪( https://github.com/mapbox/mapbox-gl-js/issues/4113 ),但是只是想知道此时是否还有其他解决方案?
I believe this will help with my problem, when ready (https://github.com/mapbox/mapbox-gl-js/issues/4113), but just wondering if there's another solution in place at this time?
更新
我尝试了几种不同的方法:
I've tried several different approaches:
-
NSPredicate(format: "'a' IN CAST(string_ids, 'NSArray<NSString>')")
出现以下错误:尚未将表达式投射到NSArray." -
NSPredicate(format: "string_ids contains[c] %@", "a")
不会出错,但没有与过滤器匹配的功能. -
NSPredicate(format: "string_ids LIKE 'a'")
出现以下错误:不支持NSPredicateOperatorType:7."
NSPredicate(format: "'a' IN CAST(string_ids, 'NSArray<NSString>')")
errors out with: "Casting expression to NSArray not yet implemented."NSPredicate(format: "string_ids contains[c] %@", "a")
does not error out, but no features match the filter.NSPredicate(format: "string_ids LIKE 'a'")
errors out with: "NSPredicateOperatorType:7 is not supported."
推荐答案
截至因此,为了结束我最初的问题的循环,该谓词现在可以按需工作:NSPredicate(format: "string_ids contains 'a'")
.
So, to close the loop on my original question, this predicate is now working as desired: NSPredicate(format: "string_ids contains 'a'")
.
这篇关于通过字符串化JSON数组属性中包含的值过滤图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!