I'm trying to parse JSON in a program built with embarcadero's c++builder (Tokyo 10.2 Update 3), which is not easy considering their severe lack of documentation.
I am using the TJSONIterator
Find
method that returns true or false if the Path (eg [0]['key']
or car.model['colour']
) you give exists in the JSON data, which according to embarcadero's documentation needs a rewinding procedure passed to the constructor of the TJSONIterator
class and if it's not there then an exception is thrown stating that.
The rewinding procedure should inherit the _di_TRewindReaderProc
interface so here is my class.
class rewindclass : public TJSONIterator::_di_TRewindReaderProc
{
public:
void __fastcall Invoke(System::Json::Readers::TJsonReader* AReader)
{
//code to rewind Iterator
Areader->Rewind();
}
};
I'm not sure what should go into the Invoke
function because as I said the documentation is useless. Obviously you have to do something with the TJsonReader
that's passed and the only function I can see that could be used is Rewind
but I don't think that's it because the only thing the documentation says about the TRewindReaderProc
is
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.
and I cannot see what else could be used instead. It says the actual data stream that provides the input must be reset but I'm not sure how to do this.
I'm using a TStringReader
to read in the JSON data which is fed into a TJsonTextReader
class constructor and that's fed into a TJSONIterator
class constructor with a class that is using the _di_TRewindReaderProc
interface.
//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);
This code compiles ok but when I debug it and step into the TJSONIterator
constructor the TJsonTextReader
is not passed through and because of that when I call the Find
method a second time it throws an exception saying no callback procedure set.
So does anyone know why the _di_TRewindReaderProc
is not being passed through and what should go into the Invoke
method?