kristijorgji / php-json-bender
一个将JSON转换为PHP数组声明的库。
1.0.0
2018-08-10 15:19 UTC
Requires
- php: >=7.1
This package is not auto-updated.
Last update: 2024-09-25 17:52:24 UTC
README
一个简单的库,用于将JSON字符串转换为PHP数组声明。
目录
安装
composer require kristijorgji/php-json-bender
示例
在控制台中运行
vendor/bin/phpJsonBender /srv/input/test.json /srv/output/test.php
第一个参数是输入JSON的实际路径。
第二个参数是所需输出的实际路径。
在我的示例中,输入文件的内容如下
[{ "created_at": "Thu Jun 22 21:00:00 +0000 2017", "id": 877994604561387500, "id_str": "877994604561387520", "text": "Creating a Grocery List Manager Using Angular, Part 1: Add & Display Items https://#/xFox78juL1 #Angular", "truncated": false, "entities": { "hashtags": [{ "text": "Angular", "indices": [103, 111] }], "symbols": [], "user_mentions": [], "urls": [{ "url": "https://#/xFox78juL1", "expanded_url": "http://buff.ly/2sr60pf", "display_url": "buff.ly/2sr60pf", "indices": [79, 102] }] }, "source": "<a href=\"http://bufferapp.com\" rel=\"nofollow\">Buffer</a>", "user": { "id": 772682964, "id_str": "772682964", "name": "SitePoint JavaScript", "screen_name": "SitePointJS", "location": "Melbourne, Australia", "description": "Keep up with JavaScript tutorials, tips, tricks and articles at SitePoint.", "url": "https://#/cCH13gqeUK", "entities": { "url": { "urls": [{ "url": "https://#/cCH13gqeUK", "expanded_url": "http://sitepoint.com/javascript", "display_url": "sitepoint.com/javascript", "indices": [0, 22] }] }, "description": { "urls": [] } }, "protected": false, "followers_count": 2145, "friends_count": 18, "listed_count": 328, "created_at": "Wed Aug 22 02:06:33 +0000 2012", "favourites_count": 57, "utc_offset": 43200, "time_zone": "Wellington" } }]
生成的输出PHP文件位于/srv/output/test.php,内容如下
<?php $array = [ '0' => [ 'created_at' => 'Thu Jun 22 21:00:00 +0000 2017', 'id' => 877994604561387500, 'id_str' => '877994604561387520', 'text' => 'Creating a Grocery List Manager Using Angular, Part 1: Add & Display Items https://#/xFox78juL1 #Angular', 'truncated' => false, 'entities' => [ 'hashtags' => [ '0' => [ 'text' => 'Angular', 'indices' => [ '0' => 103, '1' => 111, ], ], ], 'symbols' => [], 'user_mentions' => [], 'urls' => [ '0' => [ 'url' => 'https://#/xFox78juL1', 'expanded_url' => 'http://buff.ly/2sr60pf', 'display_url' => 'buff.ly/2sr60pf', 'indices' => [ '0' => 79, '1' => 102, ], ], ], ], 'source' => '<a href="http://bufferapp.com" rel="nofollow">Buffer</a>', 'user' => [ 'id' => 772682964, 'id_str' => '772682964', 'name' => 'SitePoint JavaScript', 'screen_name' => 'SitePointJS', 'location' => 'Melbourne, Australia', 'description' => 'Keep up with JavaScript tutorials, tips, tricks and articles at SitePoint.', 'url' => 'https://#/cCH13gqeUK', 'entities' => [ 'url' => [ 'urls' => [ '0' => [ 'url' => 'https://#/cCH13gqeUK', 'expanded_url' => 'http://sitepoint.com/javascript', 'display_url' => 'sitepoint.com/javascript', 'indices' => [ '0' => 0, '1' => 22, ], ], ], ], 'description' => [ 'urls' => [], ], ], 'protected' => false, 'followers_count' => 2145, 'friends_count' => 18, 'listed_count' => 328, 'created_at' => 'Wed Aug 22 02:06:33 +0000 2012', 'favourites_count' => 57, 'utc_offset' => 43200, 'time_zone' => 'Wellington', ], ], ];
许可证
php-json-bender采用MIT许可证发布。有关详细信息,请参阅附带的LICENSE文件。