【发布时间】:2018-04-04 12:56:34
【问题描述】:
我正在尝试在使用 embarcadero 的 c++builder(Tokyo 10.2 Update 3)构建的程序中解析 JSON,考虑到他们严重缺乏文档,这并不容易。
我正在使用 TJSONIterator Find 方法,如果您提供的路径(例如 [0]['key'] 或 car.model['colour'])存在于 JSON 数据中,则返回 true 或 false,根据 embarcadero 的文档需要通过回绕程序到TJSONIterator 类的构造函数,如果它不存在则抛出异常说明。
倒带过程应该继承_di_TRewindReaderProc接口所以这里是我的类。
class rewindclass : public TJSONIterator::_di_TRewindReaderProc
{
public:
void __fastcall Invoke(System::Json::Readers::TJsonReader* AReader)
{
//code to rewind Iterator
Areader->Rewind();
}
};
我不确定Invoke 函数中应该包含什么内容,因为正如我所说,文档是无用的。显然,您必须对已传递的TJsonReader 做一些事情,我能看到的唯一可以使用的功能是Rewind,但我不认为就是这样,因为文档中关于TRewindReaderProc 的唯一内容是
Reference to a procedure that rewinds the input data of the specified JSON reader.
Note: TJsonReader.Rewind does not rewind the input data, it resets the state of the JSON
reader. This procedure must rewind the actual data stream that provides the input data
of the JSON reader.
我看不出还有什么可以代替的。它说必须重置提供输入的实际数据流,但我不确定如何执行此操作。
我正在使用 TStringReader 读取 JSON 数据,该数据被馈送到 TJsonTextReader 类构造函数中,并被馈送到带有使用 _di_TRewindReaderProc 接口的类的 TJSONIterator 类构造函数中。
//create rewindclass
rewindclass *rewind = new rewindclass();
//setting up TJSONIterator class
TStringReader *sread = new TStringReader(this->Memo1->Text);
TJsonTextReader *jread = new TJsonTextReader(sread);
TJSONIterator *jit = new TJSONIterator(jread, *rewind);
这段代码可以编译,但是当我调试它并进入TJSONIterator 构造函数时,TJsonTextReader 没有通过,因此当我第二次调用Find 方法时它会抛出一个异常,说没有回调程序集。
那么有谁知道为什么_di_TRewindReaderProc 没有被传递,Invoke 方法应该进入什么?
【问题讨论】:
标签: c++ json c++builder