0

我在做正则表达式时遇到了麻烦,而且我不知道如何提出问题,所以比文字更好,这是一个例子

细绳

"medias": [
    {
      "height": 800,
      "id": "",
      "origin": "google",
      "thumbnail": {
        "height": 94,
        "url": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTF_KeDfHAxLuvCoYkuKUcwPKpxHfjt19g-E0uhsV20rLGf6VbJ--NFKCuO",
        "width": 150
      },
      "title": "144779-cat-cats.jpg",
      "type": "image",
      "url": "https://lh4.googleusercontent.com/-bemqYIv9dPw/UTsFD0yJsBI/AAAAAAAAAZI/1zrKmdolPLY/s0-d/144779-cat-cats.jpg",
      "width": 1280
    },
    {
      "height": 300,
      "id": "",
      "origin": "google",
      "thumbnail": {
        "height": 94,
        "url": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcR60TwME2D02rjeROsOlHSMdk5AkrtwPwJIhsXBqoOoISUA95rXpKXihL4",
        "width": 124
      },
      "title": "cats-in-sink.jpeg",
      "type": "image",
      "url": "https://lh4.googleusercontent.com/-zrZJg2qJQlI/Tg9kwdqbsrI/AAAAAAAAAEQ/Oal8KLLfItk/cats-in-sink.jpeg",
      "width": 397
    }
]

正则表达式

"medias": \[
   ([{
      "height": \d+[,|]
      "id": ".*"[,|]
      "origin": ".*"[,|]
      "thumbnail": {
        "height": \d+[,|]
        "url": ".*"[,|]
        "width": \d+[,|]
      }[,|]
      "title": ".*"[,|]
      "type": ".*"[,|]
      "url": ".*"[,|]
      "width": \d+[,|]
    }[,|]]*)[,|]
\][,|]

正则表达式的中间部分,在 () 之间,工作正常。但是当我添加media wrapper周围时,它会被破坏。

"medias": \[
 ....................
 ....................
 ...........[,|]
\][,|]

在这里你会找到匹配的中间部分

在这里你会发现完整的正则表达式被破坏

任何想法 ?

4

1 回答 1

1

json_decode()改用php中的函数

$array = json_decode($json_object);
于 2013-06-18T16:12:50.723 回答