Hướng dẫn jsonlint-php - jsonlint-php

JSON Lint

Hướng dẫn jsonlint-php - jsonlint-php

Cách sử dụng

use Seld\JsonLint\JsonParser;

$parser = new JsonParser();

// returns null if it's valid json, or a ParsingException object.
$parser->lint($json);

// Call getMessage() on the exception object to get
// a well formatted error message error like this

// Parse error on line 2:
// ... "key": "value"    "numbers": [1, 2, 3]
// ----------------------^
// Expected one of: 'EOF', '}', ':', ',', ']'

// Call getDetails() on the exception to get more info.

// returns parsed json, like json_decode() does, but slower, throws
// exceptions on failure.
$parser->parse($json);

Bạn cũng có thể chuyển các cờ bổ sung cho JsonParser::lint/parse điều chỉnh chức năng:

  • JsonParser::DETECT_KEY_CONFLICTS ném một ngoại lệ vào các khóa trùng lặp.
  • JsonParser::ALLOW_DUPLICATE_KEYS thu thập các khóa trùng lặp. ví dụ. Nếu bạn có hai khóa
    $parser = new JsonParser;
    try {
        $parser->parse(file_get_contents($jsonFile), JsonParser::DETECT_KEY_CONFLICTS);
    } catch (DuplicateKeyException $e) {
        $details = $e->getDetails();
        echo 'Key '.$details['key'].' is a duplicate in '.$jsonFile.' at line '.$details['line'];
    }
    0, chúng sẽ kết thúc là ____10 và
    $parser = new JsonParser;
    try {
        $parser->parse(file_get_contents($jsonFile), JsonParser::DETECT_KEY_CONFLICTS);
    } catch (DuplicateKeyException $e) {
        $details = $e->getDetails();
        echo 'Key '.$details['key'].' is a duplicate in '.$jsonFile.' at line '.$details['line'];
    }
    2.
  • $parser = new JsonParser;
    try {
        $parser->parse(file_get_contents($jsonFile), JsonParser::DETECT_KEY_CONFLICTS);
    } catch (DuplicateKeyException $e) {
        $details = $e->getDetails();
        echo 'Key '.$details['key'].' is a duplicate in '.$jsonFile.' at line '.$details['line'];
    }
    3 phân tích cú pháp cho các mảng kết hợp thay vì các đối tượng STDCLASS.

Example:

$parser = new JsonParser;
try {
    $parser->parse(file_get_contents($jsonFile), JsonParser::DETECT_KEY_CONFLICTS);
} catch (DuplicateKeyException $e) {
    $details = $e->getDetails();
    echo 'Key '.$details['key'].' is a duplicate in '.$jsonFile.' at line '.$details['line'];
}

Lưu ý: Thư viện này có nghĩa là phân tích JSON trong khi cung cấp thông báo lỗi tốt về lỗi. Không có cách nào nó có thể nhanh như PHP bản địa

$parser = new JsonParser;
try {
    $parser->parse(file_get_contents($jsonFile), JsonParser::DETECT_KEY_CONFLICTS);
} catch (DuplicateKeyException $e) {
    $details = $e->getDetails();
    echo 'Key '.$details['key'].' is a duplicate in '.$jsonFile.' at line '.$details['line'];
}
4. This library is meant to parse JSON while providing good error messages on failure. There is no way it can be as fast as php native
$parser = new JsonParser;
try {
    $parser->parse(file_get_contents($jsonFile), JsonParser::DETECT_KEY_CONFLICTS);
} catch (DuplicateKeyException $e) {
    $details = $e->getDetails();
    echo 'Key '.$details['key'].' is a duplicate in '.$jsonFile.' at line '.$details['line'];
}
4.

Bạn nên phân tích cú pháp với

$parser = new JsonParser;
try {
    $parser->parse(file_get_contents($jsonFile), JsonParser::DETECT_KEY_CONFLICTS);
} catch (DuplicateKeyException $e) {
    $details = $e->getDetails();
    echo 'Key '.$details['key'].' is a duplicate in '.$jsonFile.' at line '.$details['line'];
}
5 và khi nó không thể phân tích lại với Seld/JsonLint để lấy lại thông báo lỗi thích hợp cho người dùng. Xem ví dụ như cách nhà soạn nhạc sử dụng thư viện này:

Cài đặt

Để cài đặt nhanh với nhà soạn nhạc sử dụng:

$ composer require seld/jsonlint

JSON Lint có thể dễ dàng được sử dụng trong một ứng dụng khác nếu bạn có trình tải tự động PSR-4 hoặc nó có thể được cài đặt thông qua trình soạn thảo để sử dụng làm CLI sử dụng. Sau khi được cài đặt thông qua Trình soạn thảo, bạn có thể chạy lệnh sau để xua lại tệp JSON hoặc URL:

Yêu cầu

  • Php 5.3+
  • [Tùy chọn] Phpunit 3.5+ để thực hiện bộ kiểm tra (PHPUNIT --Version)

Gửi lỗi và yêu cầu tính năng

Lỗi và yêu cầu tính năng được theo dõi trên github

Tác giả

Jordi Boggiano - - http://twitter.com/seldaek

Giấy phép

JSON Lint được cấp phép theo giấy phép MIT - xem hồ sơ cấp phép để biết chi tiết

Sự nhìn nhận

Thư viện này là một cổng của Thư viện JsonLint JavaScript.

Được cung cấp bởi: jsonlint_1.4.0-1build1_all

Hướng dẫn jsonlint-php - jsonlint-php

TÊN

       jsonlint-php - JSON Lint command line interface

TÓM TẮT

       jsonlint file [options]

TÙY CHỌN

       -q, --quiet
              Cause jsonlint to be quiet when no errors are found

       -h, --help
              Show this message

TÊN¶

JsonLint -php - giao diện dòng lệnh json lint

TÓM TẮT¶

Tệp JsonLint-Php [Tùy chọn] file [options]

TÙY CHỌN¶

-Q, --quietCause jsonLint im lặng khi không tìm thấy lỗi h,--helpshow tin nhắn này, --quietCause jsonlint to be quiet when no errors are found-h, --helpShow this message

Ký hiệu đối tượng JavaScript

  • Giới thiệu
  • Installing/Configuring
    • Yêu cầu
    • Cài đặt
    • Cấu hình thời gian chạy
    • Loại tài nguyên
  • Hằng số được xác định trước
  • JSONEXICEVECTE - Lớp Jsoneoxception
  • Jsonsonserializable - Giao diện Jsonsonserializable
    • Jsonsonserializable :: jsonserialize - Chỉ định dữ liệu cần được tuần tự hóa thành JSON
  • Chức năng JSON
    • JSON_DECODE - Giải mã chuỗi JSON
    • JSON_ENCODE - Trả về biểu diễn JSON của một giá trị
    • JSON_LAST_ERROR_MSG - Trả về chuỗi lỗi của cuộc gọi cuối cùng json_encode () hoặc json_decode ()
    • JSON_LAST_ERROR - Trả về lỗi cuối cùng xảy ra

Không có người dùng đóng góp ghi chú cho trang này.