0

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:

"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?

4

3 回答 3

2

使用JavaScriptSerializerMicrosoft在此处记录的类来反序列化 JSON。这将比 RegEx 容易得多。

于 2012-07-26T19:10:09.107 回答
0

我在互联网上找到了两个相似的页面。可以使用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);
    }
}

因为http://oe1.orf.at/programm/konsole/tag/20120726您应该将 for 循环更改为

foreach(var item in dynObj.list)
于 2012-07-26T19:38:06.287 回答
0

试试这个:

(?<=[\n\r])[^\S\n\r]*"info"[^\S\n\r]*:[^\S\n\r]*"(?<info>.*?)",?[^\S\n\r]*(?=[\n\r])
于 2012-07-27T14:15:45.393 回答