0

我有一些像数据爬取 URL 的 Json

[[["oppl.lr",[,,,,,,,,,,,[[[[[,"A Google User"]
,,,,1]
,3000,,,"Double tree was ok, it wasnt super fancy or anything. Its good for families and  just relaxing by the pool. Service was good, and rooms were kept neat.","a year ago",["http://www.ma..",,1],,"","",""]
]
,["Rooms","Service","Location","Value"]
,[]

使用 php json_decode() 函数是不可能解析的。是否有任何库或其他东西可以让我将其转换为常规 json 以便我的任务更容易?否则我知道我必须写正则表达式。

提前致谢。

4

1 回答 1

0

根据您的评论。如果您的数据是

[["oppl.lr",[,,,,,,,,,,,[[,"A Google User"],"",""],""]]]

如果你能以某种方式将数据发送到客户端。然后它是一个有效的 javascript 数组。您可以处理数据@client 端或使用

JSON.stringify([["oppl.lr",[,,,,,,,,,,,[[,"A Google User"],"",""],""]]]);

并将数据发送回服务器

"[["oppl.lr",[null,null,null,null,null,null,null,null,null,null,null,[[null,"A Google User"],"",""],""]]]"

否则通过 php 你可以使用这个函数

function getValidArray($input) {
   $input = str_replace(",,", ',"",', $input);
   $input = str_replace(",,", ',"",', $input);
   $input = str_replace("[,", '["",', $input);
   return eval("return $input;");
}

您可以根据需要优化上述功能。

于 2012-07-24T09:25:07.833 回答