解析带有错误 json 的文本文件 - PHP
我收到了一个格式错误的 json 文件,我必须使用 PHP 来解析它。
{timestamp":"2022-03-25 00:25:41.476+00","order_id":"1659616"}{timestamp":"2022-03-25 00:18:51.892+00","order_id":"1560808"}{timestamp":"2022-03-25 00:23:52.267+00","order_id":"1727305"}
我想使用:
foreach(file("abovefile.txt") as $line) {
}
问题是我没有新行。如何读取括号之间的内容,然后提取所有条目的时间戳和 order_id?
最好的方法是什么?
I was given a badly formatted json file and I have to parse it using PHP.
{timestamp":"2022-03-25 00:25:41.476+00","order_id":"1659616"}{timestamp":"2022-03-25 00:18:51.892+00","order_id":"1560808"}{timestamp":"2022-03-25 00:23:52.267+00","order_id":"1727305"}
I want to use:
foreach(file("abovefile.txt") as $line) {
}
The issue is I don't have a new line. How do I read in between the brackets and then extract timestamp and order_id for all entries?
What is the best way to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这是格式并且完全一样,您可以使用以下“过程”解决此问题:
If this is the format and it's exactly like that, you can solve this with this "procedure":