定制 crocodile2u/json-streamer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

crocodile2u/json-streamer

Composer 安装命令:

composer require crocodile2u/json-streamer

包简介

Memory-efficient and fast streaming JSON parser

README 文档

README

Memory-efficient and fast streaming JSON parser.

Example: parsing GeoJson from a gzipped JSON file containing a FeatureCollection, streaming it feature by feature. The second parameter to JsonStreamer constructor is the path in your JSON structure that contains the array that you want streamed. In this example, GeoJson's FeatureCollection is an object that has a 'features' property with an array of feature objects.

$fp = fopen("compress.zlib://" . __DIR__ . "/Fiji.GeoJson.gz", "r");
$parser = new \JsonStreamer\JsonStreamer($fp, "features");
foreach ($parser as $val) {
    echo substr(json_encode($val), 0, 100)."\n\n";
}

The array that you'd like to stream can contained deeply nested in the JSON structure. Here, the data that we're interested in, are located at level 3. If you were to access this array in Javascript, that would be like this:

let container = {
    "lvl1": {
        "lvl2": {
            "lvl3": [
                [1, 2, 3],
                [1, 2, 3, 4],
                [1, 2, 3, 4, 5],
                [1, 2, 3, 4, 5, 6]
            ]
        }
    }
}
let data = container.lvl1.lvl2.lvl3

To iterate through the same data in PHP with JsonStreamer, do the following:

$fp = fopen('data://text/plain,' . $json,'r');
$parser = new \JsonStreamer\JsonStreamer($fp, "lvl1.lvl2.lvl3");
foreach ($parser as $val) {
    echo json_encode($val) . "\n\n";
}

JsonStreamer has been built with GeoJson in mind, and is only capable of iterating over JSON arrays (possibly nested inside wrapper objects). However, it does it's work quite efficiently, as compared to other streaming JSON parsers. I was able to parse huge GeoJson files containing enormous GeoJson shapes (multipolygons) tens times faster and using ~4 times less memory than any other streaming JSON parser I tried. I'm saying this without any intent to undermine those projects: they are generic JSON parsers while JsonStreamer only does a very specific kind of job.

统计信息

  • 总下载量: 482
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-07-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固