[英]Regex between quotes
I have to parse as part of a project a playlist file: 我必须解析作为项目播放列表文件的一部分:
The layout looks like this: 布局如下所示:
{
"info" : "",
"time" : "05:00",
"url_stream" : "http://loopstream01.apa.at/?channel=oe1&id=20120726_0500_1_2_nachrichten_XXX_w_",
"day_label" : "26.07.2012",
"short_title" : "Nachrichten",
"url_detail" : "",
"url_json" : "/programm/308178/konsole",
"parts" : [],
"tag" : "",
"id" : "308178",
"title" : "Nachrichten",
"url_playlist" : "/programm/308178/playlist"
},........... and so on
now i want to get the values of the "properties". 现在我想获得“属性”的值。 I tried this one
我试过这个
"info" : "(?<info>(([^"]*)))", ....
but it is buggy because the it is possible that there is something like this: 但它有bug,因为有可能有这样的事情:
"info" : "Hello "World" this was a test", “信息”:“你好”世界“这是一个考验”,
you see that "World" is also in "" and so it gets buggy. 你看到“世界”也在“”,所以它变得越来越多。 Does anyone has a good and clean solution for me?
有没有人为我提供一个良好而干净的解决方案?
I found two similar pages on internet. 我在网上发现了两个类似的页面。 They can be parsed using Json.Net as below:
可以使用Json.Net解析它们 ,如下所示:
using (var wc = new WebClient())
{
string url = "http://derruki.dyndns.org/oe1rip/json-list-source.php";
string json = wc.DownloadString(url);
dynamic dynObj = JsonConvert.DeserializeObject(json);
foreach(var item in dynObj)
{
Console.WriteLine("INFO:{0}\nTITLE:{1}\nURL:{2}\n\n",
item.info, item.short_title, item.url_stream);
}
}
For http://oe1.orf.at/programm/konsole/tag/20120726
you should change for loop as 对于
http://oe1.orf.at/programm/konsole/tag/20120726
您应该将for循环更改为
foreach(var item in dynObj.list)
试试这个:
(?<=[\n\r])[^\S\n\r]*"info"[^\S\n\r]*:[^\S\n\r]*"(?<info>.*?)",?[^\S\n\r]*(?=[\n\r])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.