QJsonParseError Struct

QJsonParseError 类用于报告 JSON 解析过程中的错误。更多

Header: #include <QJsonParseError>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

注意:该结构中的所有函数都是可重入的

公共类型

enum ParseError { NoError, UnterminatedObject, MissingNameSeparator, UnterminatedArray, MissingValueSeparator, …, GarbageAtEnd }

公共函数

QString errorString() const

公共变量

QJsonParseError::ParseError error
int offset

详细说明

另请参阅 Qt 中的 JSON 支持以及保存和加载游戏

成员类型文档

enum QJsonParseError::ParseError

该枚举描述了在解析 JSON 文档时发生的错误类型。

常量说明
QJsonParseError::NoError0未发生错误
QJsonParseError::UnterminatedObject1对象未正确使用结尾大括号结束
QJsonParseError::MissingNameSeparator2缺少分隔不同项目的逗号
QJsonParseError::UnterminatedArray3数组未正确使用结尾方括号结束
QJsonParseError::MissingValueSeparator4缺少分隔对象内键与值的冒号
QJsonParseError::IllegalValue5值不合法
QJsonParseError::TerminationByNumber6在解析数字时输入流结束(从 6.9 版起,不再返回该值)
QJsonParseError::IllegalNumber7数字不完整
QJsonParseError::IllegalEscapeSequence8输入中出现非法转义序列
QJsonParseError::IllegalUTF8String9输入中出现非法 UTF8 序列
QJsonParseError::UnterminatedString10字符串未以引号结束
QJsonParseError::MissingObject11预期会出现一个对象,但无法找到
QJsonParseError::DeepNesting12JSON 文档嵌套太深,解析器无法解析
QJsonParseError::DocumentTooLarge13JSON 文档太大,解析器无法解析
QJsonParseError::GarbageAtEnd14解析后的文档末尾包含额外的垃圾字符

成员函数文档

QString QJsonParseError::errorString() const

返回与报告的 JSON 解析错误相应的人可读信息。

另请参阅 error

成员变量文档

QJsonParseError::ParseError QJsonParseError::error

包含解析错误的类型。如果文档解析正确,则等于QJsonParseError::NoError

另请参阅 ParseErrorerrorString()。

int QJsonParseError::offset

包含发生解析错误的 UTF-8 字节数组中的字节偏移。

另请参阅 error,errorString() 和QJsonDocument::fromJson()。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.