我正在关注来自web服务api的json响应.我想从json中提取产品数据.我还想使用AFNetworking实现这一点.
{"products": [
{
"product_id": "1170",
"name": "zzzz®",
"sort_order": 0,
"brand": "zzzas",
"product_category_id": "1090",
"location_ids": [
"1078"
],
"icon_url": "http://zzzzz.com/media/2502/zzzz.png",
"icon_date": "Wed, 07 Nov 2012 14:03:47 GMT",
"thumbnail_url": "http://zzzz.com/media/2591/zzdfs.png",
"thumbnail_date": "Wed, 07 Nov 2012 14:04:02 GMT"
},
{
"product_id": "1126",
"name": "ddddd®",
"sort_order": 1,
"brand": "dddsas",
"product_category_id": "1110",
"location_ids": [
"1095"
],
"icon_url": "http://zzzzz.com/media/2507/ddddd.png",
"icon_date": "Wed, 07 Nov 2012 14:03:48 GMT",
"thumbnail_url": "http://zzzzz.com/media/2596/sssds.png",
"thumbnail_date": "Wed, 07 Nov 2012 14:04:05 GMT"
}
]}
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议一种方法来完成这些.事情.
你好,我想提取 () 之间的文本。
例如 :
(some text) some other text -> some text
(some) some other text -> some
(12345) some other text -> 12345
Run Code Online (Sandbox Code Playgroud)
括号之间的字符串的最大长度应为 10 个字符。
(TooLongStri) -> nothing matched because 11 characters
Run Code Online (Sandbox Code Playgroud)
我目前拥有的是:
let regex = try! NSRegularExpression(pattern: "\\(\\w+\\)", options: [])
regex.enumerateMatchesInString(text, options: [], range: NSMakeRange(0, (text as NSString).length))
{
(result, _, _) in
let match = (text as NSString).substringWithRange(result!.range)
if (match.characters.count <= 10)
{
print(match)
}
}
Run Code Online (Sandbox Code Playgroud)
效果很好,但匹配的是:
(some text) some other text -> (some text) …Run Code Online (Sandbox Code Playgroud)