【发布时间】:2014-02-25 16:44:41
【问题描述】:
假设我有一个看起来像这样的字符串
{
"_links": {
"next": "https://api.twitch.tv/kraken/users/test_user1/follows/channels?direction=DESC&limit=25&offset=25",
"self": "https://api.twitch.tv/kraken/users/test_user1/follows/channels?direction=DESC&limit=25&offset=0"
},
"follows": [
{
"created_at": "2013-06-02T09:38:45Z",
"_links": {
"self": "https://api.twitch.tv/kraken/users/test_user1/follows/channels/test_channel"
},
"channel": {
"banner": null,
"_id": 1,
"url": "http://www.twitch.tv/test_channel",
"mature": null,
"teams": [
],
"status": null,
"logo": null,
"name": "test_channel",
"video_banner": null,
"display_name": "test_channel",
"created_at": "2007-05-22T10:37:47Z",
"delay": 0,
"game": null,
"_links": {
"stream_key": "https://api.twitch.tv/kraken/channels/test_channel/stream_key",
"self": "https://api.twitch.tv/kraken/channels/test_channel",
"videos": "https://api.twitch.tv/kraken/channels/test_channel/videos",
"commercial": "https://api.twitch.tv/kraken/channels/test_channel/commercial",
"chat": "https://api.twitch.tv/kraken/chat/test_channel",
"features": "https://api.twitch.tv/kraken/channels/test_channel/features"
},
"updated_at": "2008-02-12T06:04:29Z",
"background": null
}
},
...
]
}
频道中的部分将出现 x 次,其中“名称”部分具有不同的值。我将如何使用正则表达式或不获取上面代码中值为“test_channel”的“名称”中的值。它出现的所有时间,然后将其打印到文本框
我认为我管理的唯一部分是正则表达式部分
string regex = @"(""name"":)\s+(\w+)(,""video_banner"")";
【问题讨论】:
-
是json。使用 json 解析器而不是正则表达式。
-
您正在寻找有关如何使用此正则表达式在文本字符串中查找匹配项的建议?