#1 Re: mORMot 1 » JSON serialization array of array of double » 2021-01-08 23:09:29

Vitaly, your solution works fine... and makes me more and more smarter;-)

Any idea how to parse in dependence of geometry type (geojson)?
"Point" => TPoint2D ([13.4578, 52.6037])
"LineString" => array of TPoint2D (my json example)
"Polygon" => array of array of TPoint2D   "[[[13.3142, 52.5014], [13.3103, 52.6055], [13.3326, 52.5558], [13.3142, 52.5014]]]"
...
In the callback function, the data must be read (or write) in differently depending on the "type". Alternatively, the coordinates could be delivered as json-string and evaluated separately.

ab wrote:

You don't need to put a RawUTF8 within the record.

Without RawUTF8 in TPoint2D my Delphi2007 compiler fails with "E2134 Typ besitzt keine Typinformation" (missing TypeInfo)

&type works fine. JSON read and write looks fine.

  
LCoord.lng := GetNextItemDouble(P);
LCoord.lat := GetNextItemDouble(P, ']');  // this works. 

Thanks to all!

#2 Re: mORMot 1 » JSON serialization array of array of double » 2021-01-06 19:04:43

This fails with "Unregistered ptCustom for TJSONRecordTextDefinition.AddItem(: TDOUBLEDYNARRAY).
@macfly: I want to read the json data format [[13.3568, 52.6183], [... with RegisterCustomJSONSerializerFromText

I'm afraid I have to do it with TDocVariantData.

#3 mORMot 1 » JSON serialization array of array of double » 2021-01-05 22:47:13

robs
Replies: 20

How can I get a record with JSON data in the structure of "array of array of double" or in JSON "[[number, number]]" ?
Every try with RegisterCustomJSONSerializerFromText in Delphi 2007 (best Delphi ever;-) fails.
Is it possible without using TDocVariantData?

Sample JSON data:
{
	"type": "LineString",
	"coordinates": [[13.3568, 52.6183], [13.4167, 52.5581], [13.3467, 52.5412], [13.3192, 52.5302]]
}

type 
TGeometry = packed record
        coordinates: array of array of double; // better for me: array of TPoint2D (=record lng,lat:double end;)
	AType: RawUTF8;
end;

here my negativ tested definitions:
const 
__TGeometry ='coordinates array of array of double AType RawUTF8';
__TGeometry ='coordinates [[double]] AType RawUTF8';
__TGeometry ='coordinates array of [double] AType RawUTF8';
__TGeometry ='coordinates array of array[0..1] of double AType RawUTF8';

TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TGeometry), __TGeometry ).
    Options := [soReadIgnoreUnknownFields, soWriteHumanReadable]; // => exception

Board footer

Powered by FluxBB