我在制作正则表达式时遇到了麻烦,我不知道如何制定问题,所以比言语更好,这里有一个例子
"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": \[
....................
....................
...........[,|]
\][,|]
Here you'll find the middle part matching
And here you'll find the complete regexp that is broken
任何想法?
答案 0 :(得分:1)
使用php中的函数json_decode()
$array = json_decode($json_object);